Page 1 of 1

REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 2:55 pm
by Andy Parker

I'm trying to update an array field in a database using rest services, and have followed the instructions by Max found here:

https://getsatisfaction.com/apperyio/...

I can get the service to work when testing, I can change the value of the array field in question on the row in question by using the correct object_id, and a value
eg ["Andy","Dave","John"] and this is successful and reflected when I check the database.

However, when I call the service from within my code, I get error 400 (Bad Request).
I have added javascript to the service to display the object ID in the browser console (and thats correct) and the data to update (the above is an example), and its correct.

Can you help please?


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 3:13 pm
by Kateryna Grynko

Hi Andy,

What can you see on console Network tab? Please look at not only service response code, but its headers also.


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 3:29 pm
by Andy Parker

Thanks Katya,

Here is what I see on the Network tab:
(I have xxxx'd out the full object ID)

REQUEST:
51baexxxxxxxxxxxxxxfadaa8
api.appery.io/rest/1/db/collections/users
OPTIONS
200
OK
text/plain
jquery-1.8.2.js:8416
Script
318 B
0 B
170 ms
130 ms

RESPONSE:
51baexxxxxxxxxxxxxxfadaa8
api.appery.io/rest/1/db/collections/users
PUT
400
Bad Request
application/json
Other
373 B
101 B
168 ms
168 ms


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 3:54 pm
by Kateryna Grynko

You send us a short form. Please provide us with the full text with headers. Also please close cookies and safety keys.

See an example below: Image
Image


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 5:56 pm
by Andy Parker

Here's the header:
Image

And heres the other screens, it seems as though the error is the data being sent for the array. This works on the test, any ideas?
Image
Image
Image


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 6:03 pm
by Andy Parker

And here is the working screenshot from the REST Test page.
Image


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 6:09 pm
by Kateryna Grynko

You send an array incorrectly. For request parameter followers_username add JS code that returns an array (not the string JSON.stringify).


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 6:11 pm
by Andy Parker

cool, many thanks.

Odd that it works from the Test page as a string ?


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 6:14 pm
by Kateryna Grynko

I think yes.


REST Service Update - Error 400 (Bad Request)

Posted: Tue Jun 18, 2013 6:30 pm
by Andy Parker

Thanks again Katya, I've added the code below and this works great!

Image