Page 1 of 1

rest api call example on livecodeserver

Posted: Tue Jun 02, 2020 5:22 am
by keliko
Hai,

I use HostM for livecode hosting. can you give me example how to translate curl form parsepaltfom to livecode server code.

Code: Select all

curl -X POST \
  -H "X-Parse-Application-Id: APPLICATION_ID" \
  -H "X-Parse-REST-API-Key: REST_API_KEY" \
  -H "X-Parse-Revocable-Session: 1" \
  -H "Content-Type: application/json" \
  -d '{"username":"cooldude6","password":"p_n7!-e8","phone":"415-392-0202"}' \
  https://YOUR.PARSE-SERVER.HERE/parse/users
this is my livecode lc

Code: Select all

<?lc

get shell(curl -X POST \
  -H "X-Parse-Application-Id: GrktQDet4zmzA4z0gxf1ygPhGLXUErPQPnUuQiFNeZ" \
  -H "X-Parse-REST-API-Key: ROi2aFXVAZkbEyrDOsXmXPZgAGrQneFUPMzQXFhzNx" \
  -H "X-Parse-Revocable-Session: 1" \
  -H "Content-Type: application/json" \
  -d '{"username":"cooldude6","password":"p_n7!-e8","phone":"415-392-0202"}' \
  https://pg-app-13t3b9qqzidvx36sygwz74dqddly89iobjp5.scalabl.cloud/1/classes/_User)

   
?>
but i get error.

Code: Select all

file "/home/ua856198/public_html/blastblast.com/api.lc"
  row 3, col 17: Function: separator is not a ',' (POST)
  row 3, col 17: shell: bad parameter (POST)
  row 3, col 17: Expression: bad function (POST)
  row 3, col 17: get: bad expression (POST)
  row 3, col 17: script: bad statement (POST)
I want to do a rest api call from the livecode server. Thanks

Re: rest api call example on livecodeserver

Posted: Tue Jun 02, 2020 5:54 am
by bangkok
Pseudo code :

and provided you have the string

{"username":"cooldude6","password":"p_n7!-e8","phone":"415-392-0202"}

in tPostData

Code: Select all

 put "X-Parse-Application-Id: APPLICATION_ID"&cr into tHeader
 put "X-Parse-REST-API-Key: REST_API_KEY"&cr after tHeader
 put "X-Parse-Revocable-Session: 1"&cr after tHeader
 put "Content-Type: application/json"&cr after tHeader

put "https://YOUR.PARSE-SERVER.HERE/parse/users" into tURL

 put true into tSettings["no_reuse"]
 put true into tSettings["use_ssl"]
   
put tsNetPostSync(tUrl, tHeader, tPostData, tResponseHeaders, tResult, tBytes, tSettings) into tData

put tData
I might misunderstood your question. If you want to use shell : then you need to work on the query (handle all the " with the word quote) etc.

Like

Code: Select all

get shell("curl -X POST  blabla "&quote&" http blablab"&quote)

Re: rest api call example on livecodeserver

Posted: Tue Jun 02, 2020 7:16 am
by keliko
tsnet can use livecode server?

Re: rest api call example on livecodeserver

Posted: Tue Jun 02, 2020 10:28 am
by bangkok
keliko wrote:
Tue Jun 02, 2020 7:16 am
tsnet can use livecode server?
Oops. It seems... no (on HostM)

I did a :

put tsNetVersion()

error message...

I just opened a ticket to ask.

Re: rest api call example on livecodeserver

Posted: Tue Jun 02, 2020 12:41 pm
by bangkok
Ok, HostM is fast. :D

So yes it's possible to get LC Server Indy.

"To proceed with this, simply email a copy of your LiveCode Indy receipt to clientcare.7883119@hostm.com and we will be able to upgrade your hosting account for you."

Re: rest api call example on livecodeserver

Posted: Tue Jun 02, 2020 4:39 pm
by keliko
yes I use host m for LC server, but I don't know how to use tsnet for the server. maybe anyone can help me?
:roll:

Re: rest api call example on livecodeserver

Posted: Tue Jun 02, 2020 5:10 pm
by FourthWorld
tsNet is not needed for most http calls. It has useful options for many network operations, but for http the basics needed are built into LiveCode.

See the POST command in the Dictionary, and the See Alsos noted there.