I'm using cURL in PHP to do this.

The syntax I'm looking for is for the last key/value pair in this array:

$node_data = array(
'title' => $title,
'type' => 'place',
'body[und][0][value]' => $body,
'field_place_country[und][0][value]' => $field_place_country,
'field_place_latitude[und][0][value]' => $field_place_latitude,
'field_place_longitude[und][0][value]' => $field_place_longitude,
'field_legacy_id[und][0][value]' => $field_legacy_id,
'field_place_alternate_name[und][0][value]' => 'test a',
'field_place_related_document[und][0][target_id]' => $field_place_related_document_id,
);

What should the syntax be, rather than: field_place_related_document[und][0][target_id]

?

Thank you,
Doug

Comments

DUG1138’s picture

Version: 7.x-3.x-dev » 7.x-3.1
Component: Miscellaneous » Documentation
DUG1138’s picture

Title: How can I create a node that includes an 'entity reference' field using the REST service? » Using the REST service to create a node that includes an 'entity reference' field. What is the syntax for this?
s.daniel’s picture

Not sure if this is the same kind of reference you are looking for in any case it might help someone who stumbles upon this issue: http://drupal.org/node/1354202

DUG1138’s picture

Title: Using the REST service to create a node that includes an 'entity reference' field. What is the syntax for this? » Using the REST service to create a node that includes an 'entity reference' field. [[Is anyone still developing this module?]]
marcingy’s picture

Status: Active » Closed (won't fix)

With an attitude like that......it is volunteer project if you want an urgent solution go pay someone.

DUG1138’s picture

Ok, Marc.

I'll pay you $10, if you can answer the question with a solution that works.

note: there can be more than one entity reference in the data I'm importing, so I'm going to need something that works along these lines:

field_place_related_document[und][0][target_id]
field_place_related_document[und][1][target_id]
field_place_related_document[und][2][target_id]
...
field_place_related_document[und][n][target_id]

Will PayPal work for you?

DUG1138’s picture

Status: Closed (won't fix) » Active
DUG1138’s picture

Title: Using the REST service to create a node that includes an 'entity reference' field. [[Is anyone still developing this module?]] » Using the REST service to create a node that includes an 'entity reference' field. ($10 if you know how to do this)
marcingy’s picture

Status: Active » Closed (won't fix)

I don't want paid I simply have a) no time b) no desire to answer your question given your attitude. If you want paid help go and create an entry on drupal.org/paid-services.

DUG1138’s picture

Status: Closed (won't fix) » Active
marcingy’s picture

Status: Active » Closed (won't fix)

Please do not re-open this issue, it is going to stay closed as I say if you want paid help use the appropriate channel on d.o.

azicchetti’s picture

If the field is using the autocomplete widget, you have to use this format:

'field_place_related_document[und][0][target_id]' => "anything ({$field_place_related_document_id})",

The form handler automatically gets the node id from the parenthesis.

azicchetti’s picture

Issue summary: View changes

minor syntax adjustment

gejo’s picture

I had this problem with an ajax call (phonegap app).
Syntax suggested by #12 worked for me, as I'm using the autocomplete widget at the field definition:
...'&node[field_entityreference][und][0][target_id]=anything (' + encodeURIComponent(nid_reference) + ')'...

Also suggested here.
Thanks to azicchetti.