rest api call example on livecodeserver

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
keliko
Posts: 85
Joined: Thu Aug 01, 2019 8:15 am

rest api call example on livecodeserver

Post by keliko » Tue Jun 02, 2020 5:22 am

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

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: rest api call example on livecodeserver

Post by bangkok » Tue Jun 02, 2020 5:54 am

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)

keliko
Posts: 85
Joined: Thu Aug 01, 2019 8:15 am

Re: rest api call example on livecodeserver

Post by keliko » Tue Jun 02, 2020 7:16 am

tsnet can use livecode server?

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: rest api call example on livecodeserver

Post by bangkok » Tue Jun 02, 2020 10:28 am

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.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: rest api call example on livecodeserver

Post by bangkok » Tue Jun 02, 2020 12:41 pm

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."

keliko
Posts: 85
Joined: Thu Aug 01, 2019 8:15 am

Re: rest api call example on livecodeserver

Post by keliko » Tue Jun 02, 2020 4:39 pm

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:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: rest api call example on livecodeserver

Post by FourthWorld » Tue Jun 02, 2020 5:10 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “CGIs and the Server”