Services 3 and Node Reference
Question
I am working with the module services 3 (D7) and I am calling the Drupal method from a Java client. I can login (and keep the session in the cookie) and I can create a simple node.
But I can't set a Node Reference Field.
To find the way to do it, I first looked to the node structure (with the reference field) in my drupal site:
[field_presta_presta_suivi] => Array
(
[und] => Array
(
[0] => Array
(
[nid] => 43
)
)
)
So, in my Java Client, I created a function to reproduce this structure:
public static HashMap addReferenceField(String field, String language, String type_ref,Object value, HashMap node, int delta ){
HashMap f = new HashMap();
HashMap p = new HashMap();
Object[] i = new Object[delta+1];
HashMap val = new HashMap();
val.put(type_ref, value);
i[delta] = val;
p.put(language, i);
f.put(field, p);
return f;
}
This function is used to create a HashMap that will be add to the parameter of the service 'node.create'.
This function works with a User Refence Field (which has the same node struture), but when I used it for a node reference, the server returned "Not Acceptable".
I have already passed a lot of time on it and didn't find any example or similar case, so here my question:
How to you use services 3 (D7) to create a node with a node reference field ?
Solution
The default resources of Services are all fairly broken, because they rely on simulating an actual form submission (blah!). I recommend using those provided by Services Entity instead.
OTHER TIPS
No need to go for an another module, following json structure will help you to create node reference field,
"field_specialization":
{
"und":
{
"value":"10"
}
}