Hello!
I've recently started working on a watch app that makes a web request to a third party API. After plenty of fiddling however, I have landed on this error that I can't seem to figure out.
Here is a copy of the code I'm using. I've edited the sample WebRequest project that comes with the SDK installation to meet my needs:
function makeRequest() as Void { var url = "https://api-link-here/" + path-param-here + "/rest-of-api-link-here"; var params = null; var options = { :method => Communications.HTTP_REQUEST_METHOD_GET, :headers => { "Content-Type" => REQUEST_CONTENT_TYPE_JSON, "Authorization" => authorization-token-here, // set headers "APIVersion" => api-version-here}, :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON }; 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 } }
I call the makeRequest() method from a BehaviorDelegate but am presented with a Response: -200 error code in the Debug Output. This indicates that my request header fields are invalid.
I have included 3 header fields. The APIVersion header field is one required by this particular third party API.
Does anybody have any idea what I'm doing wrong - I suspect it's a syntax error somewhere in my code.
Thanks in advance!