Services 7.x-3.7
I'm trying to POST a new node to my Drupal server (http://blah/rest/node), but the server is always returning an error with the string:
Not found: Could not find the controller
I have the node resource enabled for my endpoint. Within the node resource, the update option is enabled, which, according to the comments, is for both updating and creating nodes:
update: Update or create Node entities based on UUID
I've tracked it down to services/servers/rest_server/includes/RESTServer.inc (which I have not modified) where it looks for the valid operations for the given resource. For a POST, the operation it is looking for in the code is create, not update. But in the $resources array, it only has update.
Any help is appreciated.
Comments
Hi I had same problem
Hi I was facing the same issue.
You need to add header while sending the POST method
key: Content-Type and Value = application/json then pass the values in json format. the key of the key-value pair should be relevant to the fields present in the node fields
Query: curl -X POST -H "Accept-Encoding: gzip" -H "Content-Type: application/json; charset=utf-8"
This helped me and I hope it will help you too.
When you post data then what
When you post data then what response you get?. Might be your are missing X-CSRF-Token in your header.
creating node with html format
Hi there,
I managed to consume services by creating a custom node type with custom fields. One of theese fields is a "Long text and summary", and I want it's value to be filtered_html formatted.
I've been trying many solutions but didn't manage to figure out how to do it. It is always stored as "plain_text" in the DB.
Please find below my php code.
$node_data is the array of post vars passed to curl
ordine is the node type
order_body is the field I want to be formatted as filtered_html
$node_data = array(
'type' => 'ordine', //content type e.g. 'page' or 'article'
'title' => $order_title,
'field_order_body[und][0]' => array('value' => $order_body),
);
Any ideas?
Thanks in advance
Create a Node through Drupal UI First
Create a Node through the Drupal UI first by and select your desired input format.
Then use services to retrieve the node:
http://example.com/my_endpoint/node/123.json
Then examine the JSON, that should reveal how you need to specify the input format from within the body field.
Hi Tyler,Thanks alot, I
Hi Tyler,
Thanks alot, I indeed examined the json of my entity "order_body", it's like this:
"field_order_body":{
"und":[
{
"value":"test<b>ciao</b>",
"summary":"",
"format":"plain_text",
"safe_value":<p>test<b>ciao</b></p>",
"safe_summary":""
}
]
}
So I tried like this but it did not work
<?php
$node_data = array(
'type' => 'ordine',
'title' => $order_title,
'field_order_body[und][0]' => array('value' => $order_body,'format' => 'filtered_html'),
);
?>
The format is still stored as plain_text in the DB
ok solved
It was a permissions problem....
The user I was logging in did not have "Use the Filtered HTML text format" permission enabled.
It's a bug anyways since the service should return a permission error. Instead it creates the node with plain_text format instead of filtered_html