Get the site ID from the REST API during avi:forge:installed:app

For the trigger “avi:forge:installed:app”:
How do we get the site ID from the REST API - How do we get the site ID during the install event?
We couldn’t call this function from the webhook: “https://api.atlassian.com/oauth/token/accessible-resources

Hi Philipp, the ids you get back in the response from https://api.atlassian.com/oauth/token/accessible-resources are cloudIds.

In Forge Triggers you can get the cloudId from either the context or the event itself e.g.

export async function run(event, context) {
	console.log(context.installContext);
	console.log(event.context.cloudId);
}
1 Like

@AdamMoore Thank you. That worked. And how can we retrieve the cloudId inside a ForgeUI component, e.g. IssueGlance PanelDetails?

For example, that’s what we tried and it didn’t work:

const PanelDetails = () => {
  const [siteId, setSiteId] = useState<string>('');
  useEffect(async () => {
    const endpoint = 'https://api.atlassian.com/oauth/token/accessible-resources';
    const res = await fetch(endpoint, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      }
    });
    const jsonData = await res.json();
    console.log('AR', jsonData);
    setSiteId(jsonData[0].id);
  }, []);
  return (
    <Fragment>
      <Text>{siteId}</Text>
    </Fragment>
  );
};

In UI Kit, you can use the useProductContext hook to get the cloudId.

@AdamMoore Thank you so much. That worked. :hugs:
Another follow up question: Can we also get the organizationName and the site url form the trigger “avi:forge:installed:app” event?

No, sorry, you’ll need to call the REST API

@AdamMoore The REST API you provided doesn’t seem to include organizationName and site url. Is baseUrl reliable to extract the site url? Where do we get the organizationName?

Yeah, baseUrl and siteUrl are the same. Sorry, I’m not actually sure if the organizationName is available. I’ll try and find out.