Page 1 of 1

REAST API help

Posted: Thu Feb 06, 2014 5:07 pm
by ckelly5430
Hi Livecoders,

I’ve subscribed to a SMS text message service that uses a simple REST or SOAP API

I’ve built an application in Delphi that use SOAP/ActiveX to dispatch the message and read the response but would really like to use the REST API in a Livecode desktop application, I’m new to Livecode and struggling to understand where to start with this simple task.

Could somebody be kind enough to write me some pseudo code and point me in the right direction: the key elements are:

URL: <THE_URL_TO_SEND_TO>

Method: POST

Authentication: Basic / Session

Example request:

<?xml version='1.0' encoding='UTF-8'?>
<messages>
<accountreference>MYACCOUNTDETAILS</accountreference>
<message>
<to>44xxxxxxxxxx</to>
<body>Hello World!</body>
</message>
</messages>

Response: Content Type: application/xml HTTP Status Code: 200

Thanks in advance.

I did originally post this message in the "complete beginners" forum but now think it may be better posted here. - apologies for double postings as this has now become quite pressing

Col.

Re: REAST API help

Posted: Thu Feb 06, 2014 5:12 pm
by FourthWorld
Moderation note: A duplicate of this thread was formerly in the "Complete Beginners" section, since deleted so those wanting to reply to this request can know where to do so. Going forward please make only one thread for a given topic, per the Forum Guidelines at http://forums.runrev.com/viewtopic.php?f=4&t=18885. Thanks.

Re: REAST API help

Posted: Thu Feb 06, 2014 5:15 pm
by FourthWorld
See the POST command in the Dictionary. For creating the XML data that gets sent, you may also want to filter the Dictionary to find the many commands available via LiveCode's XML external, included in the LiveCode package.

Re: REAST API help

Posted: Thu Feb 06, 2014 5:19 pm
by bangkok
OK. I see 3 steps.

1 - the header
It's necessary to create a special header.
Put it into a variable (or a field) and then

Code: Select all

  libURLSetCustomHTTPHeaders field "MyHeader"
2 - the query
Here it's very simple, a simple POST command

Code: Select all

post tMyQuery to url "http://www.cccc.com/webservice/CAdxSubProgramXml"
put it into tResult
3 - the server will send back XML data, right ?
Here, you'll need some XML commands.
I advise the stack from Trevor DeVore of Blue Mango Learning Systems.

Re: REAST API help

Posted: Thu Feb 06, 2014 5:49 pm
by ckelly5430
Thanks for your response - what do I need to put into the "libURLSetCustomHTTPHeaders" ?

Re: REAST API help

Posted: Thu Feb 06, 2014 6:05 pm
by FourthWorld

Re: REAST API help

Posted: Thu Feb 06, 2014 11:04 pm
by bangkok
ckelly5430 wrote:Thanks for your response - what do I need to put into the "libURLSetCustomHTTPHeaders" ?
Here is a header I use for a webservice.

Code: Select all

POST /adxwsvc/services/CAdxSubProgramXml HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 1871
Host: www.www.www.ww:18980
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
-> you have to get the length of your POST query, and copy it into the header (line content-length).