Page 1 of 1

Problem with a REST API Call

Posted: Thu Jan 11, 2024 3:13 pm
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?

Re: Problem with a REST API Call

Posted: Thu Jan 11, 2024 4:31 pm
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

Re: Problem with a REST API Call

Posted: Thu Jan 11, 2024 4:44 pm
by pink
Tried that as well, same result.

Re: Problem with a REST API Call

Posted: Thu Jan 11, 2024 7:43 pm
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.

Re: Problem with a REST API Call

Posted: Thu Jan 11, 2024 8:24 pm
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.

Re: Problem with a REST API Call

Posted: Thu Jan 11, 2024 10:57 pm
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…

Re: Problem with a REST API Call

Posted: Fri Jan 12, 2024 5:48 pm
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.