08-10-2022 04:42
08-10-2022 04:42
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,
08-10-2022 13:27
08-10-2022 13:27
I think you have to use a numeric IP; see here.
And https probably won't work unless you have a non-self-signed certificate.
08-12-2022 15:02
08-12-2022 15:02
Dear Gondwana,
Thank you for your help. I will try again by follow the solution.
08-18-2022 20:00 - edited 08-18-2022 20:02
08-18-2022 20:00 - edited 08-18-2022 20:02
08-19-2022 01:08
08-19-2022 01:08
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.