When using the simulator I have no issue using fetch and grabbing some data from an API, then passing it to the from the companion app to the fitbit with the messenging service. When i deploy it to the actual fitbit I'm getting a null. Am i missing a cert or something?
Answered! Go to the Best Answer.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
I'm pretty sure fetch is only supporting https. The simulator doesn't have that restriction though.
Best Answerexport function usgsCall(site){
const host = `http://waterservices.usgs.gov/nwis/iv/?format=json&sites=${site}&period=P1D`;
return fetch(host, {
method : "GET"})
.then(function(response){
return response.json();
})
.then(function(data) {
let obj = data.value.timeSeries;
console.log(data.value.timeSeries);
for (var key in obj){
if (obj.hasOwnProperty(key))
{
if(obj[key].variable.unit.unitCode === "ft3/s"){
var cfs = obj[key].values[0].value[0].value;
var four = cfs - obj[key].values[0].value[12].value;
var two = cfs - obj[key].values[0].value[8].value;
var half = cfs - obj[key].values[0].value[2].value;
}
if(obj[key].variable.unit.unitCode === "ft"){
var feet = obj[key].values[0].value[0].value;
}
}
}
return {cfs: cfs, feet: feet, four: four, two: two, half: half};
})
.catch(function(error) {
console.log(error, 'error');
});
}The error will be throw but wont actual print anything.
Best AnswerIts the fetch itself where i'm running into an issue i believe.
Best AnswerThis is the error I'm pulling.
SyntaxError: Unexpected end of JSON input
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
I'm pretty sure fetch is only supporting https. The simulator doesn't have that restriction though.
Best AnswerI can call an HTTP web server from a local network when running on the versa but I can't do an HTTP request to a public IP address, I'm also getting a null.
Making HTTP requests should be allowed.
Nonetheless, Where can we find more info about what's allowed and what not?
Best Answer