Updating channel settings – field descriptions via python
I’m trying to update my channel settings via a PUT request using Python and the Requests library. I’m following the example and guidance that’s shown here: Mathworks-WriteSettings.
Following the example URL as a guide I get a URL parameter string that appears to meet the requirements, however I get the following error mesage: {"status":"401","error":{"error_code":"error_auth_required","message":"Authorization Required","details":"Please provide proper authentication details."}}
I have found a couple posts with similar issues and the fix action guidance was to ensure that the channel ID and API write keys are correct and match each other (i.e. the right write key for the right channel). I have double-checked mine a dozen times and I’m successfully sending actual data to the channel using the same key, so I’m pretty confident those parameters are correct.
In the documentation, the example URL is shown in two ways — one way has ".json" appended to the primary URL (before the ? parameters). There’s another example further down the page that shows the URL without .json appended.
If I remove the .json from my request, I do actually get a response that says I’ve successfully updated the channel, such as:
{‘api_key’: ‘<the_actual_api_key’, ‘field1’: ‘Air Temp’, etc……..}
Field names updated successfully!
However, no updates actually appear in the channel settings! As I understand it, the only purpose of the .json tag is to let ThingSpeak know whether to provide its response in json format as opposed to html (which appears to be the default response format).
I can post the entire python code if useful but it mostly it just creates the api_url shown below.
Any and all suggestions welcome — thank you!!
Python code:
% # This passes authentication, returns 200 – but doesn’t effect any actual settings changes…
api_url = ‘https://api.thingspeak.com/channels/2475657?api_key=<actual_key>&field7=AirTemp’
% # This returns 401
api_url = ‘https://api.thingspeak.com/channels/2475657.json?api_key=<actual_key>&field7=AirTemp’I’m trying to update my channel settings via a PUT request using Python and the Requests library. I’m following the example and guidance that’s shown here: Mathworks-WriteSettings.
Following the example URL as a guide I get a URL parameter string that appears to meet the requirements, however I get the following error mesage: {"status":"401","error":{"error_code":"error_auth_required","message":"Authorization Required","details":"Please provide proper authentication details."}}
I have found a couple posts with similar issues and the fix action guidance was to ensure that the channel ID and API write keys are correct and match each other (i.e. the right write key for the right channel). I have double-checked mine a dozen times and I’m successfully sending actual data to the channel using the same key, so I’m pretty confident those parameters are correct.
In the documentation, the example URL is shown in two ways — one way has ".json" appended to the primary URL (before the ? parameters). There’s another example further down the page that shows the URL without .json appended.
If I remove the .json from my request, I do actually get a response that says I’ve successfully updated the channel, such as:
{‘api_key’: ‘<the_actual_api_key’, ‘field1’: ‘Air Temp’, etc……..}
Field names updated successfully!
However, no updates actually appear in the channel settings! As I understand it, the only purpose of the .json tag is to let ThingSpeak know whether to provide its response in json format as opposed to html (which appears to be the default response format).
I can post the entire python code if useful but it mostly it just creates the api_url shown below.
Any and all suggestions welcome — thank you!!
Python code:
% # This passes authentication, returns 200 – but doesn’t effect any actual settings changes…
api_url = ‘https://api.thingspeak.com/channels/2475657?api_key=<actual_key>&field7=AirTemp’
% # This returns 401
api_url = ‘https://api.thingspeak.com/channels/2475657.json?api_key=<actual_key>&field7=AirTemp’ I’m trying to update my channel settings via a PUT request using Python and the Requests library. I’m following the example and guidance that’s shown here: Mathworks-WriteSettings.
Following the example URL as a guide I get a URL parameter string that appears to meet the requirements, however I get the following error mesage: {"status":"401","error":{"error_code":"error_auth_required","message":"Authorization Required","details":"Please provide proper authentication details."}}
I have found a couple posts with similar issues and the fix action guidance was to ensure that the channel ID and API write keys are correct and match each other (i.e. the right write key for the right channel). I have double-checked mine a dozen times and I’m successfully sending actual data to the channel using the same key, so I’m pretty confident those parameters are correct.
In the documentation, the example URL is shown in two ways — one way has ".json" appended to the primary URL (before the ? parameters). There’s another example further down the page that shows the URL without .json appended.
If I remove the .json from my request, I do actually get a response that says I’ve successfully updated the channel, such as:
{‘api_key’: ‘<the_actual_api_key’, ‘field1’: ‘Air Temp’, etc……..}
Field names updated successfully!
However, no updates actually appear in the channel settings! As I understand it, the only purpose of the .json tag is to let ThingSpeak know whether to provide its response in json format as opposed to html (which appears to be the default response format).
I can post the entire python code if useful but it mostly it just creates the api_url shown below.
Any and all suggestions welcome — thank you!!
Python code:
% # This passes authentication, returns 200 – but doesn’t effect any actual settings changes…
api_url = ‘https://api.thingspeak.com/channels/2475657?api_key=<actual_key>&field7=AirTemp’
% # This returns 401
api_url = ‘https://api.thingspeak.com/channels/2475657.json?api_key=<actual_key>&field7=AirTemp’ write channel settings MATLAB Answers — New Questions