Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

REST Service Update - Error 400 (Bad Request)

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?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

REST Service Update - Error 400 (Bad Request)

Hi Andy,

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

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

REST Service Update - Error 400 (Bad Request)

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

REST Service Update - Error 400 (Bad Request)

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

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

REST Service Update - Error 400 (Bad Request)

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

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

REST Service Update - Error 400 (Bad Request)

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

REST Service Update - Error 400 (Bad Request)

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

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

REST Service Update - Error 400 (Bad Request)

cool, many thanks.

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

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

REST Service Update - Error 400 (Bad Request)

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

Image

Return to “Issues”