sending a JSON string

Douglas Ruisaard dougr at telus.net
Thu Oct 18 15:54:45 EDT 2018


let me start by apologizing for my screw up... after looking even further into many more forum responses, I found that there is YET ANOTHER key used for a DELETE ... once I put that in Andre's code... guess what? .... it works perfectly!!!

So pat yourself on the back, Andre! and thanks ever so much!  Now onto the next challenge... "bulk" uploading a whole slew of data point at once.

Cheers
Doug

Douglas Ruisaard
Trilogy Software
(250) 573-3935


> 
> Message: 4
> Date: Wed, 17 Oct 2018 09:14:38 -0700
> From: "Douglas Ruisaard" <dougr at telus.net>
> To: <use-livecode at lists.runrev.com>
> Subject: Re: sending a JSON string
> Message-ID: <125f01d46634$8249bc70$86dd3550$@net>
> Content-Type: text/plain;	charset="us-ascii"
> 
> Thanks very much, Andre!  I appreciate the assistance.  I am sure the two "keys" are correct as I use
> them in another portion of the application (an ESP8266 module which sends data to ThingSpeak).  A
> subsequent direct message from you mentioned "Charles Proxy" as an inspector for HTML messaging.
> THAT's a huge hint and I'll be installing it to see what exactly LC is sending.
> 
> The ThingSpeak community is very active and I'll submit a request for assistance to it.  I thought I'd
> start with this forum since it is very responsive and knowledgeable... Also my lack of good working
> understanding about LC's HTML and overall web features and functions left me thinking I was doing
> something wrong in LC.  With Andre's attempt generating a similar response to what I was getting, it
> helps vindicate my uncertainty about LC's ability to generate an appropriate message to ThingSpeak.
> 
> if I find a solution, I'll certainly let this board know.
> 
> In the meantime, if ANYONE has any other suggestions, I'd be extremely grateful!
> 
> Cheers
> Doug
> 
> Douglas Ruisaard
> Trilogy Software
> (250) 573-3935
> 
> >
> > Message: 3
> > Date: Wed, 17 Oct 2018 00:10:05 +0100
> > From: Andre Alves Garzia <andre at andregarzia.com>
> > To: How to use LiveCode <use-livecode at lists.runrev.com>
> > Cc: Douglas Ruisaard <dougr at telus.net>
> > Subject: Re: sending a JSON string
> > Message-ID: <41683bda-81ae-ac2e-1542-7d98f19ece82 at andregarzia.com>
> > Content-Type: text/plain; charset=utf-8; format=flowed
> >
> > Douglas,
> >
> > I am pasting some code I've built here that should do what you want
> > but when I try it, it returns a
> > 401 error which is an authentication error.
> > On that manual page you linked there is a notice about API keys and
> > Channel keys, so maybe the key on this email is not the correct one.
> > This is the code (and yes, it is dead ugly):
> >
> > *on*mouseup
> >
> > *local*tHeaders, tResult
> >
> > *put*emptyintofld"output"
> >
> > *put*"Content-Type: application/x-www-form-urlencoded"intotHeaders
> >
> > *put*libURLFormData("api_key", "EQKTUQQKVH83D1RE") intotFormData
> >
> > *put*tsNetCustomUpload("1",
> > "https://api.thingspeak.com/channels/564256/feeds.json", "DELETE",
> > tHeaders, "transferComplete",
> > tFormData) intotResult
> >
> > *end*mouseup
> >
> > *on*transferComplete pID, pResult, pBytes, pCurlCode
> >
> > *local*tData, tHeaders, tResult, rError
> >
> > *if* pCurlCode isnot0*then*
> >
> > *put*tsNetRetrError(pID) & crafterfld"output"
> >
> > *end* *if*
> >
> > *put*tsNetRetrData(pID, tError) intotData
> >
> > *put*"Server returned:"& tData & crafterfld"output"
> >
> > *put*"Headers"&& tsNetRetrSentHeaders("1", rError) & crafterfld"output"
> >
> > *put*tResult & cr& tHeaders & cr& pResult & cr& tData afterfld"output"
> >
> >  ?? tsNetCloseConn pID
> >
> > *end*transferComplete
> >
> >
> >
> > On 10/16/2018 9:12 PM, Douglas Ruisaard via use-livecode wrote:
> > > I'll start by apologizing for my abysmal familiarity with HTTP,
> > > JSON, and URL's ... I'm hoping
> > someone will have pity and give me a hand!
> > >
> > > I am trying to send a "command" to a ThingSpeak channel, which is
> > > very successfully receiving data
> > from a simple little ESP8266 module.  Periodically, I need to clear
> > the data from this channel.  I want to do so from LC.. NOT the
> > ESP8266.  I just can't seem to "coordinate" the instructions from the
> > ThingSpeak site to DELETE this data (not the channel, just the data within) with an LC function /
> code.
> > >
> > > The link to the ThingSpeak page I am referring to is:
> > > https://www.mathworks.com/help/thingspeak/clearchannel.html?searchHi
> > > gh
> > > light=delete%20channel%20data&s_tid=doc_srchtitle#d120e16923
> > >
> > > but in essence, I interpret the content to assert the following:
> > >
> > > Access the following URL:
> > > "https://api.thingspeak.com/channels/564256/feeds.json" where
> > > "564256" is
> > the channel I wish to clear.
> > >
> > > Send the JSON "command": "DELETE https://api.thingspeak.com/channels/564256/feeds.json
> > > 			       api_key= EQKTUQQKVH83D1RE"
> > >
> > > 				where "EQKTUQQKVH83D1RE" is my account api-key for writing to
> > > the ThingSpeak channel
> > >
> > > if successful, ThingSpeak responds with: "[]" ... an empty JSON
> > > array
> > >
> > >
> > > In LC, I've tried the following (and several variations):
> > >
> > > on mouseUp
> > >     put empty into field "Output"
> > >     put "https://api.thingspeak.com/channels/564256/feeds.json" into tUrl
> > >     put "DELETE https://api.thingspeak.com/channels/564256/feeds.xml"
> > > & return & "api_key=EQKTUQQKVH83D1RE" into JsonCmd
> > >
> > >     -- Send a HTTP DELETE request
> > >     put tsNetCustomSync(tUrl, JsonCmd, tHeader, tResponseHeaders,
> > > tResult, tBytes) into tData
> > >
> > >     -- If this is not the case, we will inform the user
> > >     put tResult into field "Output"
> > >
> > > end mouseUp
> > >
> > > I get a tResult of 0 (zero) ... but the data is NOT cleared.
> > >
> > > I have also tried the following:
> > >
> > > on mouseUp
> > >       put empty into field "Output"
> > >       put "https://api.thingspeak.com/channels/564256/feeds.json?api_key=EQKTUQQKVH83D1RE" into
> tUrl
> > >       put "DELETE
> > > https://api.thingspeak.com/channels/564256/feeds.json" & return &
> > > "api_key=EQKTUQQKVH83D1RE" into tMessage["text"]
> > >
> > >       put ArrayToJSON(tMessage) into tMessage
> > >
> > >       set the httpHeaders to "Content-type: application/json"
> > >
> > >       post tMessage to url tUrl
> > >
> > >       put it into field "Output"
> > >
> > > end mouseUp
> > >
> > > But that only "creates" a new entry in the channel with all of the data fields empty.
> > >
> > > I'm sure it's the way in which I am trying to send the "DELETE"
> > > command but I just can't see how to
> > do it correctly.
> > >
> > > I'd be grateful for any assistance.
> > >
> > >
> > > Douglas Ruisaard
> > > Trilogy Software
> > > (250) 573-3935
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > use-livecode mailing list
> > > use-livecode at lists.runrev.com
> > > Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> > > http://lists.runrev.com/mailman/listinfo/use-livecode
> >





More information about the use-livecode mailing list