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: 272
Joined: Wed Mar 12, 2014 6:18 pm

Problem with a REST API Call

Post by pink » Thu Jan 11, 2024 3:13 pm

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: 615
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Problem with a REST API Call

Post by AndyP » Thu Jan 11, 2024 4:31 pm

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 Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

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

Re: Problem with a REST API Call

Post by pink » Thu Jan 11, 2024 4:44 pm

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

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

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Problem with a REST API Call

Post by stam » Thu Jan 11, 2024 7:43 pm

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: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Problem with a REST API Call

Post by SparkOut » Thu Jan 11, 2024 8:24 pm

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: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Problem with a REST API Call

Post by stam » Thu Jan 11, 2024 10:57 pm

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: 272
Joined: Wed Mar 12, 2014 6:18 pm

Re: Problem with a REST API Call

Post by pink » Fri Jan 12, 2024 5:48 pm

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

Return to “Talking LiveCode”