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 ?

  • 1
    After a few try, I've found that I can add a Node Reference Field just by using the title (whithout the NID). I think this is due to the widget autocomplete. I am still looking to find a way to pass the node reference field by his NID. – user1241 Jul 11 '11 at 7:32
  • 3
    I don't know if it will help, but I ran into a similar issue with an older version of services. I set the node reference field to use select list widget and the problem went away. – jkopel Jan 27 '12 at 4:42

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.

| improve this answer | |
  • Thanks. Using Services Entity module did solve the problem , quickly! – Ajinkya Kulkarni Aug 29 '13 at 22:33

No need to go for an another module, following json structure will help you to create node reference field,

| improve this answer | |

Your Answer

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