04-20-2021 16:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-20-2021 16:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-30-2021 06:43
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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

04-30-2021 11:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-30-2021 11:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

