0

I am using Services module to create nodes via an api and am having problems using entity reference autocomplete to populate the field.

The ER field is linked to a taxonomy and uses a multi field setting so that more than one value can be set. I have tried multiple different options including a var_dump of the node entity upon insert and can see its not being set.

The following are the 6 ways I tried to set the field. Do you have any idea? I am using the latest Services module and the ER module.

{"und": ["112326"]}

{"und": [{"target_id":"112326"}]}

{"und": [{"target_id":"A S (112326)"}]}

{"und": ["A S (112326)"]}

{"und": [{"tid":"A S (112326)"}]}

{"und": [{"tid":112326}]}
0

First, to handle multi value fields you'll need this patch: https://www.drupal.org/node/2224803#comment-11477609

Second, depending on what Widget you have selected for your Entity Reference field, this does/can change what Services expects to be POST/PUT up to the server.

I personally always set the Widget as an Autocomplete, and then this JSON format is the correct one to use:

var node = {
  type: 'article',
  title: 'Hello world',
  language: 'und',
  field_foo: {
    und: [
      { target_id: '... (123)' }
    ]
  }
};

You can literally put anything you want in the position of the ..., the only thing that matters is the Entity ID is wrapped in the parenthesis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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