0

I have finally got Services up and running and setup an endpoint to nodes but can't work out how to update custom fields from a POST or PUT.

Been trawling through the docs, examples, and tutorials but none seem to offer a simple explanation of the XML payload schema to update custom fields of nodes (Using REST).

Below is an example of what I'm putting into by test client (Using REST console for Chrome plugin)

URL: http://example.com/task/node/65 Encoding: application/x-www-form-urlencoded METHOD: PUT

Payload:-

<title>New Title</title>
<body>New Body Content</body>

However this doesn't update anything, I just get the following response:-

<?xml version="1.0" encoding="utf-8"?>
<result>
    <nid>65</nid>
    <uri>http://example.com/task/node/65</uri>
</result>

It seems to create a revision and logs the update, but no fields are updated.

Can anyone advise the schema I need to follow for the payload? Thanks for any help or pointers!

EDIT: Thanks to Clive for a key pointer: Sticking ".xml" on the end of the URL seemed to make it update the body field, and then changing the content-type header to application/xml seemed to help as well.

So the following REST client config is now working:-

URL: http://example.com/service_endpoint/node/nid.xml

REQUEST METHOD: PUT

CONTENT-TYPE: application/xml

RAW PAYLOAD:-

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <name>user</name>
    <title>Change this owner!</title>
    <body>
        <und is_array="true">
               <item>
                <value>Another owner test</value>
            </item>
        </und>
    </body>
</data>

Screenshot to help anyone else using the Chrome REST Console plugin:-

enter image description here

NOTE: I removed all security for the service and content type to make testing it easier but wouldn't recommend this on a public server!

  • Are you sure the title isn't being updated? The body field is in the wrong format (needs to be a hierarchy matching the PHP $node->body[LANGUAGE_NONE][0]['value'] and so on) so that bit makes sense, but if you're getting a 200 response, and the node updated date is being updated, the title should be being updated – Clive Aug 13 '13 at 13:24
  • Aha! I just got the title working (removed the encoding from the accept header) So should the XML format be <node><body><und><value>new body value</value></und></body>? – Darren Aug 13 '13 at 13:27
  • Sorry Clive, scrub that - the title isn't getting updated :{ The Raw payload I'm passing is: "<title>Test title change</title>" and it's creating a revision but not updating the title of the content item. – Darren Aug 13 '13 at 13:35
  • Few more questions...is xml the default for that endpoint? If not, add .xml to the end of the URL you're sending to. Are you making a call to system.connect to get a session token, then to the CSRF token URL to get that token? (required as of services 3.4). There's a script using json that I know definitely works with v3.5 (found here), if you're consuming the resource in PHP it might be an idea to switch to json and try the working code as a sanity check to make sure the endpoint is functioning properly – Clive Aug 13 '13 at 13:52
  • Thanks clive, that tip of sticking .xml on the end of the URL seemed to make it jump into life.I'm actually using a web services client to test (chrome.google.com/webstore/detail/rest-console/…). – Darren Aug 13 '13 at 14:19
1

See updated EDIT above.

RAW PAYLOAD:-

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <name>user</name>
    <title>Change this owner!</title>
    <body>
        <und is_array="true">
               <item>
                <value>Another owner test</value>
            </item>
        </und>
    </body>
</data>

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.