Page 1 of 1

Error posting data to URL

Posted: Sat Mar 26, 2016 3:36 pm
by pink
I am experimenting with Backendless as an alternative to Parse, which has a REST API option.

I can send GET commands without a problem, but POST commands keep returning errors.

Here is my cURL command, which works (obviously the XXXs gave a real value):

Code: Select all

curl \
-H application-id:XXXXXXXXXXXXXX \
-H secret-key:XXXXXXXXXXXXXX \
-H Content-Type:application/json \
-H application-type:REST \
-X POST \
-v 'http://help.mad.pink/api/v1/users/register' \
-d '{"email":"greg@vadin.com", "name":"Greg", "password":"1234567890"}'
Result:

Code: Select all

{"userStatus":"ENABLED","created":1458998553000,"name":"Greg","ownerId":null,"updated":null,"email":"greg@vadin.com","objectId":"B32803F2-30E2-5333-FF0E-089885EC6B00","__meta":"{\"relationRemovalIds\":{},\"selectedProperties\":[\"password\",\"created\",\"___saved\",\"name\",\"___class\",\"ownerId\",\"updated\",\"email\",\"objectId\"],\"relatedObjects\":{}}"}
Livecode version, I took a short cut below with the quotes for simplicity in the JSON:

Code: Select all

function userReg
   put "application-id:XXXXXXXXXXXXXX " & cr into tHeaders
   put "secret-key:XXXXXXXXXXXXXX " & cr after tHeaders
   put "Content-Type:application/json" &cr after tHeaders
   put "application-type: REST"  after tHeaders
   set httpHeaders to tHeaders
   put "http://help.mad.pink/api/v1/users/register" into regURL
   put "{qqemailqq:qqgreg@vadin.comqq, qqnameqq:qqGregqq, qqpasswordqq:qq1234567890qq}" into tDATA
   replace "qq" with quote in tDATA
   post tDATA to URL regURL
   return the result
end userReg
Result:

Code: Select all

error 400 Bad Request
can anyone spot what I'm missing?

Re: Error posting data to URL

Posted: Thu Apr 14, 2016 1:06 pm
by MaxV
A very simple solution is to use shell() function:

Code: Select all

put "-H application-id:XXXXXXXXXXXXXX " & cr into tHeaders
put "-H secret-key:XXXXXXXXXXXXXX " & cr after tHeaders
put "-H Content-Type:application/json" &cr after tHeaders
put "-H application-type: REST"  after tHeaders
put "-X POST -v 'http://help.mad.pink/api/v1/users/register' "  after tHeaders
put "{qqemailqq:qqgreg@vadin.comqq, qqnameqq:qqGregqq, qqpasswordqq:qq1234567890qq}" into tDATA
replace "qq" with quote in tDATA
put " -d " & tDATA after  tHeaders
put shell("curl " & tHeaders) into myResult

Re: Error posting data to URL

Posted: Fri Apr 15, 2016 1:52 pm
by pink
well that solution would work on some, but not all systems... user would need to install cURL on Windows

does the shell command work on iOS and Android?

Re: Error posting data to URL

Posted: Fri Apr 15, 2016 3:01 pm
by Klaus
Hi Greg,
pink wrote:does the shell command work on iOS and Android?
there is no SHELL on mobile!


Best

Klaus