Hello,
I've recently started working on a watch app that makes a web request to a third party API. I'm stuck on authorization error - Response code: 401
I've included a copy of my code.
Please note I tried including the bearer token as is in String form in the params dictionary like so: "Authorization" => "Bearer secret_..."
This however resulted in the same response code of 401.
Perhaps the Authorization token needs to be added elsewhere?
Thanks in advance for the help!
function makeRequest() as Void {
var url = "https://api-url-here/"
+ Rez.Strings.PageID +
"/rest-of-api-url-here";
var params = {
"Authorization" => Rez.Strings.Authorization,
"API-Version" => Rez.Strings.ApiVersion
};
var options = {
:method => Communications.HTTP_REQUEST_METHOD_GET,
:headers => {
"Content-Type" => Communications.REQUEST_CONTENT_TYPE_JSON},
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON // set response type
};
Communications.makeWebRequest(url, params, options, method(:onReceive));
}
function onReceive(responseCode as Number, data as Dictionary?) as Void {
if (responseCode == 200) {
System.println("Request Successful"); // print success
} else {
System.println("Response: " + responseCode); // print response code
}
}