Last updated Apr 25, 2024

Calling product APIs from a remote

Once your remote backend has received a request from Forge, you can call product APIs.

Prerequisites

When setting up your app to:

  • Call a remote (from a Custom UI or UI Kit 2 frontend)
  • Send product and lifecycle events (to a remote)
  • Configure scheduled triggers to invoke a remote backend

You’ll need one of the following in your manifest.yml:

  • endpoint.auth.appSystemToken set to true
  • endpoint.auth.appUserToken set to true

Which one you need depends on whether you want to access product APIs as a generic bot user (appSystemToken) or the current user’s permission (appUserToken).

This will ensure requests to your remote contain an x-forge-oauth-system or x-forge-oauth-system header, containing a token you can use to call product and Forge storage APIs. Both of these tokens are valid for at least 55 minutes.

Getting started

Once you’ve got your token, you can use it in backend requests to Product APIs.

Node.js example

This example uses the fetch function from the node-fetch module to request data from the Confluence API:

1
2
'use strict'
import fetch from 'node-fetch';

export async function fetchFromConfluence(token, apiBaseUrl) {
  const headers = {
    Accept: 'application/json',
    Authorization: `Bearer ${token}`
  }
  return await fetch(`${apiBaseUrl}/wiki/rest/api/content`, { headers });
}

For more detail, see the Confluence node client in Bitbucket.

Java example

This example uses a GET request to call from a Confluence Content API:

1
2
public ResponseEntity<String> getContent(final String token, String baseUrl) {

    final HttpHeaders headers = new HttpHeaders();
    headers.setBearerAuth(token);

    final HttpEntity<String> entity = new HttpEntity<>(null, headers);

    final ResponseEntity<String> response =
            restTemplate.exchange(baseUrl + "/wiki/rest/api/content",
                    HttpMethod.GET, entity, String.class);

    logger.info("Response statusCode={}", response.getStatusCode());

    return response;
}

For more detail, see the Confluence java client in Bitbucket.

Product APIs

For a complete list of each of the product APIs that you can call from your remote:

Next steps

For further help, see how you can:

Rate this page: