Hi,
I’m trying to query the SmartThings API (v1.0-PREVIEW) with a Personal Token and I’m getting a CORS issue. If I do it from Postman of course it works fine.
Is there any way to use the API from a 100% client website?
Thanks!
Hi,
I’m trying to query the SmartThings API (v1.0-PREVIEW) with a Personal Token and I’m getting a CORS issue. If I do it from Postman of course it works fine.
Is there any way to use the API from a 100% client website?
Thanks!
Hello @Leandrrr,
This issue is generally triggered due to missing headers. Make sure that your HTTP requests contain the authorization header with your Personal Access Token.
Below you can find an example to get the status of a device using JQuery AJAX.
let urlGet="https://api.smartthings.com/v1/devices/deviceID/status";
$.ajax({
url:urlGet,
type:"GET",
headers:{
"Authorization":"Bearer PAT"
},
beforeSend: function(jqXHR, settings) {
console.log(settings.url);
},
success:function(result){
console.log("result",result)
},
error: function(error){
console.log("error",error)
}
})
If this answers your question, can you please mark it as solved? If not, let me know what’s going on and I can dig in further.
Thank you.
I didn’t realize that the library I’m using was adding an extra header creating the CORS issue.