Trouble posting json to

I’m trying to post a value to my account.
I just can’t seem to figure out the correct way to construct the json,
and whether to use PUT or POST (the difference?). Or perhaps the
problem is encoding? There are no errors on the Agent side, but there
is on the side. I don’t get a -200- response, and nothing is showing
up on

Here is the code that compiles ok, but doesn’t see the data.
I just hard-coded my feed_id and a value.

`// Agent POST
server.log(“ Agent: v1.0”);

device.on(“impMsg”, function(im) {
local jc="{“feed_id”:30380,“value”:“12345”}";
local body = http.jsonencode(jc);
local req = http.put(“”,
{“Content-Type”: “application/json”},body);
local res = req.sendsync();
server.log("agent res: "+res.statuscode);

You’re JSON encoding a JSON encoded string.

local jc={ feed_id:30380, value:12345 };

…would be more correct, as then http.jsonencode() will put it in string form.

You don’t need to escape this works
local jc={“feed_id”:30380,“value”:“12345”};
Also I use to test HTTP requests
And to validate my JSON

Also see example in wiki


Thanks once again.

For those like me struggling … here is what works.

The Agent:
`// Agent POST
server.log(“ Agent: v1.0”);
feedID <-30380;
sensKEY <- “FXQTYIp5aJ_U32q8j6AIEQ”;

device.on(“impMsg”, function(im) {
local dat1=im.data1;
local body = http.jsonencode({“feed_id”:feedID,“value”:dat1});
local req =“”+sensKEY,
{“Content-Type”: “application/json”},body);
local res = req.sendsync();
server.log("agent res: "+res.statuscode);

The Device (imp)
// send data to server. function send_to_sense() { local data1 = "12345"; agent.send("impMsg",{data1=data1}); }

Data 1 is coming across to just fine now.

And in a wiki example I saw, they were using http.put( )
I found with I have to use ( ).

That devwiki example (the link you gave) … that is a terrible example that they show. How can anyone new to this understand how to use it? Why don’t they explain what the variable ‘x’ looks like? That’s important, so people don’t do what I did (encoding an encode). I really hope as the agents get released to public we can post some easy to understand snippets and examples.

Agree the example is poor! I wish I was better writer and had more time to write up what I’ve learnt. I’ve just spent most my free time this week fecking about with electronics wouldn’t want to write about that :slight_smile: most of time I’m fumberling in the dark that’s why I use tools like

Hugo mentioned something about improving the way code is shown on this forum, and I mean Squirrel, PHP, etc. Once this site improved to allow a place to write-up tutorials and code examples, maybe all of us can gather these posts and make something easy to look at.

Happy to help with that