7

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 ?

2
  • 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
    Commented Jul 11, 2011 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
    Commented Jan 27, 2012 at 4:42

2 Answers 2

2

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.

1
  • Thanks. Using Services Entity module did solve the problem , quickly! Commented Aug 29, 2013 at 22:33
0

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

"field_specialization": 
{
  "und": 
       {
         "value":"10" 
       }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.