04-20-2021 16:34
04-20-2021 16:34
Hi, I am trying to set up the communication between the companion and any Web API using the Fetch function using the Fitbit Studio Simulator.
Fitbit Studio Details:
Device: Versa 3
SDK version: 5.0
Permissions: Internet & Run in background
Companion code:
import * as messaging from "messaging"
import { me as companion } from "companion"
const myHeaders = new Headers({'Content-Type': 'application/json'})
const API = 'https://rickandmortyapi.com/api/character/1'
console.log("BEFORE")
fetch(API, {
method : "GET",
headers : myHeaders,
// body: ''
})
.then((response) => {
console.log(response.json())
})
.then((data) => {
console.log(data)
})
.catch ((err) => {
console.error(err)
})
console.log("AFTER")
* Console Result *
04-30-2021 06:43
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.
04-30-2021 06:43
fetch() is promise based, so "AFTER" isn't really after the fetch occurs.
Looks like you solved this in another thread anyway.
https://community.fitbit.com/t5/SDK-Development/fetch-API-not-working-in-companion/m-p/4816981
Best Answer04-30-2021 11:26
04-30-2021 11:26
Thanks Jon, the problem I report is that the fetch was empty, not the order of the logs, but I fixed it and shared it in that link you added.
Best Answer