0

API POST of data: data missing required value
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

API POST of data: data missing required value

by IAM3358 on Fri Jan 25, 2019 7:41 am

I'm trying to send some simple data to AdafruitIO using AT command on a modem. I've got MQTT posts to work, now I need to do an HTTP POST. In my Dashboard Monitor I can see:

2019/01/25 11:25am error saving data to user_name/feeds/user_key, data missing required value

so the data is nearly there .... I've tried just about every format of json and non-json I can think of but I always get the same error. When viewing the response header at the modem I can see:

HTTP/1.1 422 Unprocessable Entity
Server: nginx
Date: Fri, 25 Jan 2019 11:25:11 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: strict-origin-when-cross-origin
X-AIO-Worker: io-rails-2
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: false
Access-Control-Request-Method: *
Access-Control-Allow-Methods: POST, PUT, DELETE, GET, OPTIONS, PATCH
Access-Control-Allow-Headers: DNT, Origin, X-Requested-With, X-AIO-Key, Content-Type, Accept, Authorization
Access-Control-Expose-Headers: X-Pagination-Limit, X-Pagination-Start, X-Pagination-End, X-Pagination-Count
Access-Control-Max-Age: 1728000
Cache-Control: no-cache

{"error":"request failed - Record invalid. Failed to save data to user_name/feeds/user_key, data missing required value"}
OK

If the Monitor can see the data arriving to the correct place and is so flexible with the data format, what is throwing the error?
Can anyone provide a CURL POST example?
I'm manually constructing the json as {"value": 123}
the url is:
https://io.adafruit.com/api/v2/user_nam ... er_AIO_key


I can't see anywhere if the data.json is required, or if it's supposed to be send.json ??

IAM3358
 
Posts: 7
Joined: Thu Jan 24, 2019 11:19 am

Re: API POST of data: data missing required value

by abachman on Fri Jan 25, 2019 10:27 am

One thing to check is that you're adding a "Content-Type: application/json" header to the HTTP request when you're sending JSON. Without the header IO assumes it's "Content-Type: application/x-www-form-urlencoded".

Have you tried adding the argument to the URL as a parameter? "https://io.adafruit.com...&value=123" As long as the value is properly url encoded, you won't have to do anything to the headers.


- adam b.

abachman
 
Posts: 278
Joined: Mon Feb 01, 2010 12:48 pm

Re: API POST of data: data missing required value

by IAM3358 on Fri Jan 25, 2019 1:51 pm

I'm giving that a try, it's a bit clumsy with AT commands but putting the Content-type in the URL might be a good solution.
Thanks for the speedy response.

IAM3358
 
Posts: 7
Joined: Thu Jan 24, 2019 11:19 am

Please be positive and constructive with your questions and comments.