I am trying to create a new node using the restws drupal module. My content type has just two fields: title and a file. However, when i send the request with following payload, i get an error. The file which i am referring in the payload is already existing on my drupal server.

URL : CMS_BASE_URL/node Method : POST


<?xml version="1.0" encoding="utf-8"?>
                <file resource="file" id="24">CMS_BASE_URL/file/24</file>
      <title>My 1st file test</title>
      <author resource="user" id="5">

Error - 406 Not Acceptable: Invalid data value given. Be sure it matches the required data type and format.

Is there any problem in the way i am sending the payload? If i remove the "file" part from the payload, it is able to create node.Please guide me if this is not correct.


Since the RESTful WS module internally uses the Entity APIs to create the content, the problem here is with the format of the data that are passed. While creating the content programmatically with the Entity API and attaching any files, you need to pass the file parameters in the below format:

// omitted rest of the code for brevity
$node->field_image[LANGUAGE_NONE][] = array(
  'fid' => $file->fid,
  'display' => 1,
  'description' => '',
node_save( $node );

Having said that, the solution to your problem would be the data in the below format:

<title>My 1st file test</title>
<author resource="user" id="5">

And the equivalent JSON would be:

    "type": "filetest",
    "title": "My 1st file test",
    "language": "en",
    "author": {
        "resource": "user",
        "id": "5"
    "field_my_file": {
        "fid": "24",
        "display": 1, // required to avoid integrity constraints voilation
        "description": "" // you may choose to omit this field
| improve this answer | |
  • How does it different from answer posted Jun 27 at 13:35 by Krishna Mohan? – Mołot Sep 9 '14 at 7:13
  • @Mołot: Observe the structure changes between the two, the actual problem mentioned here was with the linking of the existing file, and in that case you will need to pass the data in the mentioned format for it to get linked with the newly created node. – eMAD Sep 9 '14 at 8:45

I tested the following code it works fine. Replace your field machine names and bundle name accordingly. Hope it helps

Here is the XML format to send data

<und is_array="true">

Here is the JSON format

    "title": "title_of_node",
    "type": "bundle_name",
    "field_samplefile": {
        "und": [{
            "fid": "17",
            "filename": "changes.txt",
            "uri": "public://changes.txt",
            "filemime": "text/plain"
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.