Bulk update 401. error unauthorized

Is bulk update API broken? Was working , day later not working...
Tried using bulk update and get
{"status":"401","error":{"error_code":"error_auth_required","message":"Authorization Required","details":"Please provide proper authentication details."}
with this payload:
{
"write_api_key": "WRITE_API_KEY",
"updates": [{
"created_at": "2018-01-30 10:26:2 -0500",
"field1": "1.0",
"field2": "2.0"
},
{
"created_at": "2018-02-02 11:27:27 -0500",
"field1": "1.1",
"field2": "2.2",
"status": "well done"
}
]
}
And I get
{"status":"401","error":{"error_code":"error_auth_required","message":"Authorization Required","details":"Please provide proper authentication details."}
Already tried
  • new channel
  • new key
  • validated key

回答(1 个)

Vinod
Vinod 2020-10-16
Nothing has changed on the ThingSpeak end that will cause that.
Have a look at the documentation for the bulk_update endpoint. We suspect the content-type header is not specified correctly. It needs to be 'application/json' since you are sending in JSON data.

5 个评论

I've tried following the postman example and get the same errors. Single post updates work, just cant get past the bulk update errors. I've validated that I'm sending the correct header, here's some code from an ESP32 :
client.println("POST /channels/185687/bulk_update.json HTTP/1.1"); // Replace YOUR-CHANNEL-ID with your ThingSpeak channel ID
client.println("Host: api.thingspeak.com");
client.println("User-Agent: mw.doc.bulk-update (Arduino ESP32)");
client.println("Connection: close");
client.println("Content-Type: application/json");
client.println("Content-Length: " + buf.length());
client.println();
client.println(buf);
BTW, I assume this works for the free tier :-)
Vinod
Vinod 2020-10-16
编辑:Vinod 2020-10-16
Here's my cURL request that works. You can see it on my public channel.
curl --request POST 'https://api.thingspeak.com/channels/936997/bulk_update.json' --header 'Content-Type: application/json' --data-raw '{"write_api_key": "MY_WRITE_API_KEY","updates": [{"created_at": "2020-10-17 10:26:2 -0500","field1": "1.0","field2": "2.0"},{"created_at": "2020-10-17 11:27:27 -0500","field1": "1.1","field2": "2.2","status": "well done"}]}'
Can you modify it for your channel and confirm it works?
If you don't have cURL on your machine, you can try it from here: https://reqbin.com/curl
Here's a link to my request on reqbin: https://reqbin.com/po2ag36d
Thanks Vinod -- The curl works. You should add that to the documentation.
I was able to get my code working and it appears to have had something to do with how I constructed the code , maybe newlines ? not sure yet but will isolate the issue as others may have same.
Thanks!
Mario, did you isolate what it was about the way you built the data?

请先登录,再进行评论。

社区

更多回答在  ThingSpeak Community

类别

帮助中心File Exchange 中查找有关 Read Data from Channel 的更多信息

产品

标签

评论:

cog
2023-2-12

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by