Getting Started - Help!

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by gmak on February 14, 2012 at 11:12am

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.

AttachmentSize
dpm.jpg 98.49 KB
Categories: , ,

Comments

A little further along, but still struggling

Posted by gmak on February 14, 2012 at 1:45pm

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

Posted by tigreton on February 23, 2012 at 11:26am

target_id it says it is a string. Try it if you are bored ^^

You are right...

Posted by gmak on February 23, 2012 at 11:34am

and that is part of the problem.

More on this is found here (http://drupal.org/node/1440986).

this page

Posted by tigreton on February 23, 2012 at 12:06pm

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

Posted by gmak on February 23, 2012 at 12:16pm

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,

Posted by tigreton on February 23, 2012 at 12:35pm

Btw, can't you get the node, and see how is it the entityreference sent?

PS:Forget me, i never used services yet!

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /