REST API silently fails

Hi all. I’m new to the platform so possibly making a beginner mistake, but…

I’m calling the REST API in my Confluence Forge app and nothing happens. As in, there is no error, nothing in the console, nothing in the network tab. It just…doesn’t work.

I’ve tried using the example code from the docs:

import api, { route } from "@forge/api";

const response = await api.asUser().requestConfluence(route`/wiki/api/v2/pages`, {
  headers: {
    'Accept': 'application/json'
  }
});

console.log(`Response: ${response.status} ${response.statusText}`);
console.log(await response.json());

Nothing is printed to the browser or tunnel console after the await. The app keeps working, though.

Here are my permissions:

permissions:
  scopes:
    - read:page:confluence
    - storage:app

I’ve tried using some of the other REST APIs but same thing.

Update: I turned on verbose debugging in my tunnel and saw these errors but I’m not sure if they’re relevant:

t=2023-05-14T02:15:09+0000 lvl=dbug msg=http.ReadRequest id=95ee6a156b53 typ=proxy err=EOF
t=2023-05-14T02:15:09+0000 lvl=dbug msg=http.ReadResponse id=95ee6a156b53 typ=proxy err="unexpected EOF"

Any hints on how I might debug further?

Start by isolating the problem to being either your code, the request structure or the REST API endpoint.

Test the same request to the same endpoint using a REST API test tool like Postman and see what results you get.

Thanks!

I tried replacing api with a regular JS fetch and discovered it was my code. Turns I didn’t understand how useState works in Forge.

3 Likes