Problem with a REST API Call

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Problem with a REST API Call

Post by pink »

I am trying to use a Parse server which I haven't played with in a long time. I am having a problem with the REST API, all of the calls I am making are returning a "400 Bad Request Error" and my tinkering has proven futile thus far.

So as an example, I am trying to replicate the following (which works)

Code: Select all

curl -X GET 
-H "X-Parse-Application-Id: QQQQQ" 
-H "X-Parse-Master-Key: ZZZZZ" 
https://pg-app-XXXXXX.scalable.cloud/1/serverInfo
So I am doing the following:

Code: Select all

put "X-Parse-Application-Id: QQQQQ" & CRLF & "X-Parse-Master-Key: ZZZZZ"  into tHeaders
set the htmlHeaders to tHeaders
put URL("https://pg-app-XXXXXX.scalable.cloud/1/serverInfo") into tServerInfo
and I get:

Code: Select all

<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>
can anyone see a problem in my syntax?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know
AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Problem with a REST API Call

Post by AndyP »

Does it help forming the headers like below?

Code: Select all

put "X-Parse-Application-Id: QQQQQ" & cr into tHeaders
put "X-Parse-Master-Key: ZZZZZ" & cr after tHeaders
Andy .... LC CLASSIC ROCKS!
pink
Posts: 285
Joined: Wed Mar 12, 2014 6:18 pm

Re: Problem with a REST API Call

Post by pink »

Tried that as well, same result.
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know
stam
Posts: 3210
Joined: Sun Jun 04, 2006 9:39 pm

Re: Problem with a REST API Call

Post by stam »

The little info provided seems OK but I'm no expert...

Trying to imagine what the issue may be: Does the ID and masterKey need URLEncoding?

Out of curiosity, does tsNet help? eg:

Code: Select all

tsNetGet(<pConnectionID>, <pURL>, <pHeaders>, <pCallback>, [<pSettings>])

S.
SparkOut
Posts: 2984
Joined: Sun Sep 23, 2007 4:58 pm

Re: Problem with a REST API Call

Post by SparkOut »

First observation is that I think you need httpHeaders not htmlHeaders.
Maybe also CR rather than CRLF to create the headers without whitespace.
If it's not simply fixed that way, I 'd need to delve more deeply than I have opportunity for just now.
stam
Posts: 3210
Joined: Sun Jun 04, 2006 9:39 pm

Re: Problem with a REST API Call

Post by stam »

Well spotted!
For some reason I read it as httpHeaders too, but it’s not.
If that’s not a forum typo, then that is the cause…
pink
Posts: 285
Joined: Wed Mar 12, 2014 6:18 pm

Re: Problem with a REST API Call

Post by pink »

htmlHeaders was a typo when I wrote this post, it was httpHeaders in my script.

Changing CRLF to LF did the trick.

Thanks everyone for helping push me in the right direction.
Greg (pink) Miller

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