How to fetch the properties of a page in the update trigger

Hello experts,

I’m trying to receive specific properties of a page after it’s been updated. I’ve created the trigger, but I’m experiencing difficulty with the requestConfluence() function, as it appears unresponsive.

Below are the source code of the trigger and the output from the forge tunnel.

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

export async function run(event, context) {
  if (!event) {
    console.log("Invalid event");
  } else {
    const contentType=event["content"]["type"]
    if (contentType!=="page"){
      console.log(`Invalid content type '${contentType}'`, JSON.stringify(event, null, 2));
    }else{
      const contentId=event["content"]["id"]
      checkPageProperties(contentId)
    }
  }
}

async function checkPageProperties(pageId){
  const pageUrl = route`/wiki/rest/api/content/${pageId}/property` 
  console.log(pageUrl)
  const response = await api.asUser().requestConfluence(pageUrl, {
    headers: {
      'Accept': 'application/json'
    }
  });  
  console.log(`Response: ${response.status} ${response.statusText}`);
  console.log(await response.json());
}
Listening for requests...


invocation: a9dd841348584ba7 index.run
INFO    15:44:04.310  a9dd841348584ba7  ReadonlyRoute { value_: '/wiki/rest/api/content/33192/property' }

As you can see, after printing the URL, nothing happened, the trigger seems to be terminated silently.

I’ve just modified the code as below:

...
await checkPageProperties(contentId);
...

...
  const response = await api.asApp().requestConfluence(pageUrl, {
    headers: {
      'Accept': 'application/json'
    }
  });  
....

Now the output is:

Listening for requests...


invocation: 08634669e4cfcd99 index.run
INFO    16:06:03.256  08634669e4cfcd99  ReadonlyRoute { value_: '/wiki/rest/api/content/33192/property' }
INFO    16:06:03.494  08634669e4cfcd99  Response: 401 Unauthorized
INFO    16:06:03.494  08634669e4cfcd99  { code: 401, message: 'Unauthorized; scope does not match' }

OK, after adding the “read:page:confluence” permission scope, I’m able to receive a 200 response now.

And it turns out that there is no way to directly fetch properties inside a Page properties macro, sad!