1

I will try to convey this with as much detail as possible. I am trying to update a field I added to the user. Let's call the field field_test_field, it is an integer field.

This is what I'm doing so far.

1 Getting CSRF token at http://example.com/services/session/token which gives me something like Dgn6vINkdJUrqFj1XUG_DbWc6PKLxkhdgoB-z3BBsRg

2 Log in my user at http://example.com/rest/user/login.xml

headers are:

Content-type: application/xml
X-CSRF-Token: (token from #1)

Post body:

<?xml version="1.0" encoding="utf-8"?>
  <username>user</username>
  <password>mypassword</password>
</xml>

That works dandy, I get my user object and I'm logged in.

3 (this is the trouble), I want to update the field for my user.

I'm doing a PUT to http://example.com/rest/user/[uid].xml

Headers:

Content-type: application/xml
X-CSRF-Token: (token from response user object on #2)

This is the body

<?xml version="1.0" encoding="UTF-8"?>
<data>
<field_test_field>
  <und is_array="true">
    <item>
      <value>3434</value>
    </item>
  </und>
</field_test_field>
</data>

Yet the response comes back mutilated.

<?xml version="1.0" encoding="utf-8"?>
<result>
<field_test_field>
  <und is_array="true">
    <item></item>
  </und>
</field_test_field>
<uid>5</uid>
<roles is_array="true">
  <item>authenticated user</item>
</roles>
</result>

Doing stuff like x-www-form-urlencoded and putting field_test_field[und][0][value] works fine while testing, but posting actual XML makes me feel like I'm just missing some small detail in syntax. Any help would be greatly appreciated.

  • You need to send the whole user object back (not just the single field you want to update). It all goes through user_save() or some similar derivative, so it needs all the data to update properly. If the code in the question isn't just a snippet, that's likely to be the problem – Clive Sep 2 '14 at 17:21
  • You need to send the whole user object back (not just the single field you want to update). It all goes through user_save() or some similar derivative, so it needs all the data to update properly. If the code in the question isn't just a snippet, that's likely to be the problem – Clive Sep 2 '14 at 17:22
  • I returned the entire object that I got back from logging in and was getting a 500 error, I selectively removed items to find out which one was causing it, it was the user photo info from the response. Took it off, sent everything else back in, same problem, every field gets chopped off starting from anything that has is_array="true". I've never had this problem doing JSON before. – Antonio Torres Sep 3 '14 at 18:07

Your Answer

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

Browse other questions tagged or ask your own question.