5

For a custom node type, I have defined a field that is to hold an unlimited number of values from a taxonomy vocabulary that I defined.

This is what it looks like:

[field_taxonomy] => Array
  ( [und] => Array
      [0] => Array
        ( [tid] => 13 )
      [1] => Array
        ( [tid] => 14 )
      [2] => Array
        ( [tid] => 15 )
  )

This is the JSON I pass to the server during node creation (as per [1]):

'field_taxonomy':
  { '11':
    { 'tid': '11'} }

This format is accepted (i.e. no 406, which I get if I try to mirror the above structure), but when I look at the node on the server, the field does not contain any terms.

What does my request have to look like so I can succesfully set taxonomy terms on a node?

[1] What will be the post parameter when specifying vocabulary term?

4 Answers 4

3

Your request should use the following:

"field_taxonomy":{ "und": { "values": "14" }  }
0

As i understood from Services Documentation you doesn't need to create ершы sequence in the array [0],[2] etc. The Services module numbers it itself.

Also, if you are using auto complete for taxonomy you should use the term id, tid, 3 times

"field_taxonomy":  [{
  "tid":{
    "tid":"[tid:11]",
    "tid":"[tid:12]",
    "tid":"[tid:13]"
        }
}]
6
  • 1
    I'm not using autocomplete, but checkboxes for the vocabulary items. After a few hours of trial and error and a few glances at the Services source code, I was able to POST my vocabulary items in the following format: "field_taxonomy": { "und": [ 11 ] }
    – jbaiter
    Commented Oct 23, 2012 at 13:51
  • But this "field_taxonomy": { "und": [ 11 ] } doesn't work at all in my case drupal.stackexchange.com/q/47589/10671
    – khex
    Commented Oct 27, 2012 at 16:40
  • What does ершы in "you doesn't need to create ершы sequence" mean?
    – avpaderno
    Commented Oct 29, 2012 at 10:48
  • "this" - it was a russian keyboard layout
    – khex
    Commented Oct 29, 2012 at 12:45
  • 1
    In D7, a taxonomy term reference field with the autocomplete widget uses JSON like this: "field_tags":{"und":"Foo"}" When it is an autocomplete, the term name needs to be used instead of the term id. Commented Mar 24, 2014 at 15:30
0

One thing that tripped me up:

If you've created an autocomplete field for your term reference using a view, instead of passing in the term name like:

"field_vocab_tags": {
      "und": [
          {
             "target_id": "40"
          }
      ]
  }

You need to pass in the complete term title according to the view. In my case, I have the title set as:

Term Title - my_unique_id_field (tid)

so I actually have to set:

"field_vocab_tags": {
      "und": [
          {
             "target_id": "My Term Title - UNIQUE_ID_23 (40)"
          }
      ]
  }

This is specifically in the case where you have an autocomplete using views, and the view formats the title as I did above.

If you want multiple references, simply add additional arrays in your field[und] array, like so:

"field_vocab_tags": {
      "und": [
          {
             "target_id": "My Term Title - UNIQUE_ID_23 (40)"
          },
          {
             "target_id": "My Next Term Title - UNIQUE_ID_24 (41)"
          },
          {
             "target_id": "Your Term Title - UNIQUE_ID_C (42)"
          }
      ]
  }

Hope this helps someone.

-1

I used a string as tag values:

"field_tags": {
   "und": "term 1, term 2"
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.