Hi,
I've just started using Services 3 for a project where (eventually) we will be accessing Drupal via webservices. I have the modules installed and everything seems to be working in my tests.
However, as I try to start to try to create nodes, I am running into problems.
I have setup a REST server, with node as one of the resources available. I can create a node, which is stored in the database, but it is only creating the title. It appears that my formatting of the JSON query is not correct, but I can find little to suggest where my problem might lie.
The attached image shows the output of the devel module for the relevant fields.
I am using the following, at present (although I've tried some other variations):
{
"title":"Test Node",
"type":"element",
"body":[{"value":"THE BODY TEXT"}],
"field_productentityref":[{"target_id":{"target_id":"[target_id:14480]"}}]
}Please note that field_productentityref is an entityreference field.
The above query will create a node with a title, but neither the body or the field_productentityref are created.
Can anyone help with the correct syntax for the body and fieldentityref?
Many thanks.
| Attachment | Size |
|---|---|
| dpm.jpg | 98.49 KB |
Comments
A little further along, but still struggling
OK, I've managed to figure out the body part:
"body": {"und":[
{"value":"Some text here that will appear in the body","format":"plain_text"}
]
}
However, the entityreference field is still proving difficult. Based on the above, I have:
"field_productentityref": {"und":[
{"target_id":"[target_id:14480]"}
]
}
But, I cannot get the autocomplete reference field to populate.
Suggestions?
target_id it says it is a
target_id it says it is a string. Try it if you are bored ^^
You are right...
and that is part of the problem.
More on this is found here (http://drupal.org/node/1440986).
this page
could help you:
"title":"Review",
"type":"establishment_review",
"field_establishment":[
{
"nid":{
"nid":"[nid:26686]"
}
}
],
Well, that's the code, and the url:
http://drupal.org/node/1354202
I think is the same example as you. It says it is:
"how to use a node reference field with auto complete widget."
But it would be the same as you.
Thanks, I've seen the page
Thanks, I've seen the page you referred to. However, the problem seems to be that the entityreference field wants a TITLE and NID to populate an autocomplete field. This looks like "SOME NODE TITLE (124)".
Nodereference, on the other hand, seems to do a lookup with "[nid:12345]" in order to populate the field.
As far as I can see, the nodereference approach seems to be much more logical and streamlined. I'd like to see entityreference follow this. I am not clear whether this is an issue with Services or Entityreference.
Btw, can't you get the node,
Btw, can't you get the node, and see how is it the entityreference sent?
PS:Forget me, i never used services yet!