Thingspeak, Delete channel with HTTP DELETE, webwrite

6 次查看(过去 30 天)
Hey there,
I want to delete a thingspeak channel using the webwrite function. This is what it looks like:
url = ['https://api.thingspeak.com/channels/' channelID '.json']
options = weboptions('RequestMethod','delete', 'MediaType','application/x-www-form-urlencoded');
response = webwrite(url,'api_key',userAPIkey,options)
This returns status 401 Unauthorized. But if I only change the RequestMethod to 'put', I don't get any errors. But using 'put' only allows me to change the channel settings. How do I delete the channel using webwrite?

采纳的回答

Christopher Stapels
Make the api_key a querry string parameter.
url = ['https://api.thingspeak.com/channels/' channelID '.json?api_key=<userAPIKey>']
options = weboptions('RequestMethod','delete');
response = webwrite(url);
  3 个评论
Javier Garcia Montano
Still returning status 401
HELP!! D:
My code:
channelID = "..."
userAPIkey = "..."
url = ['https://api.thingspeak.com/channels/' channelID '.json?api_key=<userAPIkey>']
options = weboptions('RequestMethod','delete', 'MediaType','application/x-www-form-urlencoded');
response = webwrite(url,'api_key',userAPIkey,options)
Christopher Stapels
编辑:Christopher Stapels 2021-1-28
I was just using this code and I think this is more robust. I got extra characters when I used the above.
url = sprintf('https://dev1-web.thingspeak.com/channels/%d.json?api_key=%s',channelID,userAPI);
options = weboptions('RequestMethod','delete', 'MediaType','application/x-www-form-urlencoded');
response = webwrite(url,options)
but make sure channelID is a number, not a string. (no quotes)

请先登录,再进行评论。

更多回答(0 个)

社区

更多回答在  ThingSpeak Community

类别

Help CenterFile Exchange 中查找有关 Read Data from Channel 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by