POST error with JSON data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
POST error with JSON data
I am trying to POST data to Backendless (which is a backend service in case you couldn't guess)
I am out of ideas as to how to troubleshoot this, can anyone notice something wrong or recommend anything else I can check?
so theURL is: https://api.backendless.com/v1/users/login
and theData is: {"login" : "greg@mad.pink", "password" : "REDACTED"}
and when I use this command: post theData to URL theURL
I get the following:
1. it and urlResponse both say "Expecting JSON data"
2. the result says "error 400 Bad Request"
3. and from libURLLastRHHeaders() I get:
HTTP/1.1 400 Bad Request
Access-Control-Allow-Headers: Origin, application-id, application-type, Content-Type, secret-key, request, user-token
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
Access-Control-Allow-Origin: *
Content-Type: text/plain; charset=utf-8
Date: Mon, 09 May 2016 13:20:48 GMT
Server: nginx/1.8.1
Content-Length: 19
Connection: keep-alive
The following curl call works the way it should:
curl -H application-id:XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \
-H secret-key:XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \
-H Content-Type:application/json \
-H application-type:REST \
-X POST \
-v 'https://api.backendless.com/v1/users/login' \
-d '{"login" : "greg@mad.pink", "password" : "REDACTED"}'
I am out of ideas as to how to troubleshoot this, can anyone notice something wrong or recommend anything else I can check?
so theURL is: https://api.backendless.com/v1/users/login
and theData is: {"login" : "greg@mad.pink", "password" : "REDACTED"}
and when I use this command: post theData to URL theURL
I get the following:
1. it and urlResponse both say "Expecting JSON data"
2. the result says "error 400 Bad Request"
3. and from libURLLastRHHeaders() I get:
HTTP/1.1 400 Bad Request
Access-Control-Allow-Headers: Origin, application-id, application-type, Content-Type, secret-key, request, user-token
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
Access-Control-Allow-Origin: *
Content-Type: text/plain; charset=utf-8
Date: Mon, 09 May 2016 13:20:48 GMT
Server: nginx/1.8.1
Content-Length: 19
Connection: keep-alive
The following curl call works the way it should:
curl -H application-id:XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \
-H secret-key:XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX \
-H Content-Type:application/json \
-H application-type:REST \
-X POST \
-v 'https://api.backendless.com/v1/users/login' \
-d '{"login" : "greg@mad.pink", "password" : "REDACTED"}'
Greg (pink) Miller
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
Re: POST error with JSON data
Hi Greg,
This should give you what you need
Cheers,
Neil
This should give you what you need
Code: Select all
set the httpHeaders to \
"application-id: **APPIDHERE**" & cr & \
"secret-key: **SECRETKEYHERE**" & cr & \
"Content-Type: application/json"
put ("{""e&"login""e&":""e&"test@livec.com""e&",""e&"password""e&":""e&"lcisaweome""e&"}") into tPost
post tPost to url "https://api.backendless.com/v1/users/login"
Neil
Re: POST error with JSON data
I should've mentioned that I am setting the httpHeaders before the post attempt...
I did try running the command and still keep getting the "Expecting JSON Data" error
I did try running the command and still keep getting the "Expecting JSON Data" error
Code: Select all
command backend.headers pToken
put "application-id: " & backendAppID & cr into tHeaders
put "secret-key: " & backendRestID & cr after tHeaders
if pToken is not empty then
put "user-token:" & pToken & cr after tHeaders
end if
put "Content-Type:application/json" & cr after tHeaders
put "application-type: " after tHeaders
set httpHeaders to tHeaders
end backend.headers
Greg (pink) Miller
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
Re: POST error with JSON data
Hi greg,
Did you try with my example?
I get the expected response from backendless
Neil
Did you try with my example?
I get the expected response from backendless
cheers,{"lastLogin":1462805460209,"created":1462802060000,"name":"ssss","___class":"Users","user-token":"******","ownerId":*******","updated":1462803281000,"email":"test@tes.com","objectId":"F3-0434-4C8A-FF03-E12128EB7F00","__meta":"{\"relationRemovalIds\":{},\"selectedProperties\":[\"__updated__meta\",\"password\",\"created\",\"name\",\"___class\",\"ownerId\",\"updated\",\"email\",\"objectId\"],\"relatedObjects\":{}}"}
Neil
Re: POST error with JSON data
stupid me, I tried part of your code, but not all of it... I used my own headers, and therein seemed to be the problem
I was using "Content-Type:application/json"
you used: "Content-Type: application/json"
and that space made all the difference, which I find odd for three reasons:
1. the header in the cURL command did not use a space and it worked fine
2. the header worked fine for put commands, just not post commands
3. it's always worked fine without the space when interacting with other services
Thanks Neil, next time I promise not to half-ass test an example.
I was using "Content-Type:application/json"
you used: "Content-Type: application/json"
and that space made all the difference, which I find odd for three reasons:
1. the header in the cURL command did not use a space and it worked fine
2. the header worked fine for put commands, just not post commands
3. it's always worked fine without the space when interacting with other services
Thanks Neil, next time I promise not to half-ass test an example.
Greg (pink) Miller
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
Re: POST error with JSON data
Hmm that does seem like quite an annoying one. By habit, i've always put spaces after each header parameter but a space is an easy one to miss.
Glad you have it working now though
Cheers,
Neil
Glad you have it working now though
Cheers,
Neil
Re: POST error with JSON data
The frustrating part is that this is the third thing this year that I've posted on the forums that turned out to be one single missing character, the others. being a missing "s" and a missing carriage return.
Greg (pink) Miller
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
MadPink, LLC
I'm Mad, Pink and Dangerous to Know
Re: POST error with JSON data
thank you both, this thread helped me alot 6 years later.
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com