Dear Developer Team,
I have a question regarding a problem of FitBit Fetch().
In my case are unable to receive the POST fetch message data.
Although I connect the Android Phone + FitBit Sense + Computer in the same Wi-Fi,
After using Fetch API in the companion message and run the app is can not get the message result.
I have no idea where can I receive the the JSON data on Fetch POST.
as I understand is using the code like this.
Send for Post Submission in companion code.
messaging.peerSocket.addEventListener("message", (evt) => {
fetch('https://localhost:8080/fitbitdata', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
bpm: evt.data
})
})
.then(response => {
/*console.log(response);*/
})
.catch(error => {
/*console.log(error);*/
});
});
Receiver Post Route via Node JS
app.post('/fitbitdata', function(request, response){
console.log(request.data);
});
My environment using NodeJS express for running server and setting a route as127.0.0.1:8080/fitbitdata but the result is fetch is fail.
There might be something wrong in this case, is there any suggestions on in problem?
Thank you,
Best Answer
Fitbit Product Experts Alumni are retired members of the Fitbit Product Expert Program. Learn more
Hello @Guy_ ,
Thank you for your reply,
I haven't yet resolve but I am trying to use the real server instead, for example, I am using Heroku that provide https server to deploy my Node JS App. Then I plan to send the message by fetch function. I will try again on this solution.
I am using both iOS and Android but I can't get access to the localhost of them. I was trying to execute on localhost.
Best Answer