2

I set up the Services module as REST server, so I can create nodes with custom fields by REST client as in Services 3 - POST node.create with custom fields.

The settings of the Services module are the following.

Server => REST
Path to endpoint => "neoapi"
Session authentication => yes
Response formatters => json
Request parsing => application/json & application/x-www-form-urlencoded
Resource path => http://127.0.0.1/neoapi/node

Content type => mycontent
Term reference field => Autocomplete term widget (tagging)

And post next JSON data via Google Chrome Advanced Rest Client

{     
"type":"mycontent",
"title":"The New Article",
"body":{
  "und":[ {
    "value":"This is the body of new article."
    } ] },
"field_neo_terms":{
  "und":[ {
    "tid":"3"
    } ] }
}

At REST client I receive "200. OK" NID and URI of new node. But in site i have new node with title and body, but without terms and error:

Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen()
(line 441 of C:\Program Files\VertrigoServ\www\includes\unicode.inc).
Warning: preg_match_all() expects parameter 2 to be string, array in   drupal_explode_tags()
(line 7254 of C:\Program Files\VertrigoServ\www\includes\common.inc).
Warning: array_unique() expects parameter 1 to be array, null given in drupal_explode_tags()
(line 7255 of C:\Program Files\VertrigoServ\www\includes\common.inc).
Warning: Invalid argument supplied for foreach() in drupal_explode_tags()
(line 7258 of C:\Program Files\VertrigoServ\www\includes\common.inc).

3 Answers 3

3

As the documentation you linked says, the structure for the fivestar field is the following.

{
  "field_fivestar":[{
    "rating":"100",
    "target":"0"
  }]
}

Probably you are missing "target"

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

{
  "field_termins":[{
    "tid":{
      "tid":"[tid:26686]"
    }
   }]
}

Auto complete is the tricky part.

3
  • Thanks for help, I installed Drupal from scratch and nothing but with out errors ERRORS. Perhaps, this is the right way but taxonomy field still empty. Trying this way "field_taxonomy": { "und": [ 11 ] } from drupal.stackexchange.com/q/48413/10671 and nothing
    – khex
    Oct 27, 2012 at 15:18
  • The provided code is to be used only with autocomplete widget. The way you are doing in your comment is for a different kind of widget. IIRC, you should use 'your term' instead of 11 in case of free tagging
    – Mac_Weber
    Oct 29, 2012 at 0:22
  • Moreover, the error you are getting is because you are storing the data in a different way that it is expected, caused by using the API for a different widget than the one you chose for editing the node.
    – Mac_Weber
    Oct 29, 2012 at 0:29
3

It appears that the format you send to Services is dependent on what widget you have selected for your taxonomy term reference field.

For example, I have a taxonomy term reference field, single value, with a select list widget. This is the data string to use when trying to update via a POST url and data string:

&node[field_tags][und][tid]=123

The equivalent for an autocomplete widget would be:

&node[field_tags][und]=Foo

The main difference is you have to use the term name instead of the term id when the widget is set to autocomplete.

If you're using JSON to and send it to services, then the JSON should be something like this for a select list widget:

{
  field_tags:{
    und:{
      tid:123
    }
  }
}

If the widget is an autocomplete:

"field_tags":{"und":"Foo"}
0

I tried and this worked for me , created user with term reference field with widget type select list. May be it also work for node.

        $scope.user.field_preferred_fee = {}
        $scope.user.field_preferred_fee['und'] = [];
        $scope.user.field_preferred_fee['und']= [tid1,tid2,tid3];

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.