I’m trying to set up a simple html form to test json input to an agent. From the dev wiki:
Example code for JSON delivery
Here is some HTML+Javascript that sends a table (containing a string called “x” and an integer called “y”) into the Plan as a JSON string. Note that you’ll need to replace the “https:…” URL with the URL to your own HTTP in block.
`
string:
number:
`
When I try to use this to send to my agent and use http.jsondecode(), it throws an exception. Using this code on the agent:
http.onrequest(function(request, response) { try { local t = http.jsondecode(request.body); response.send(200, "OK"); } catch (e) { response.send(500, "Exception"); } });
Agent tested with your html and works a few things. I think you need to use the newer https://agent.electricimp.com/agent id url and a html form is not JSON just a set of key value pairs.
You’re mixing up an old-style web page (“HTTP in block”) with new-style (onRequest) agent code. “HTTP in blocks” automatically pluck the “value” field out of the url-encoded POST body for you, parse it as JSON, and send it to your planner (blueprint) input node. Now that everyone’s using agents, you needn’t go such a roundabout route.