Error posting data to URL

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Error posting data to URL

Post by pink » Sat Mar 26, 2016 3:36 pm

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?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Error posting data to URL

Post by MaxV » Thu Apr 14, 2016 1:06 pm

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
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Re: Error posting data to URL

Post by pink » Fri Apr 15, 2016 1:52 pm

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?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Error posting data to URL

Post by Klaus » Fri Apr 15, 2016 3:01 pm

Hi Greg,
pink wrote:does the shell command work on iOS and Android?
there is no SHELL on mobile!


Best

Klaus

Post Reply