For the complete documentation index, see llms.txt. This page is also available as Markdown.

Sample token exchange script

A single Node.js file for Cloud setup :

  • One-time consent: obtaining the initial code

  • Refresh token rotation

  • Calling the API with an access token

Before you start

  • The Cloud setup steps 1 and 2 are done, and the callback URL of your OAuth 2.0 integration is filled in as http://localhost:8080/callback (step 3, point 1).

  • You have the client id and secret of the integration (see Atlassian console > settings) , and the base URL from the Ativo REST API admin page (Jira settings > Marketplace apps > Ativo Programs > REST API).

  • Node.js 24 or newer is installed.

1

Create the files

Make an empty folder, for example ativo-api, with two files.

ativo-api.js: the script, copied from the bottom of this page.

.env: your settings. A .env file is a plain text file with one NAME=value per line. It keeps your secrets out of the script, so the script can be shared or committed and the secrets cannot.

ATIVO_API_CLIENT_ID=<client id>
ATIVO_API_CLIENT_SECRET=<secret>
ATIVO_API_BASE_URL=https://<your-site>.atlassian.net/gateway/api/svc/jira/apps/<app-id>_<environment-id>/rest/api/1

No quotes, no spaces around =. Copy the base URL exactly as the admin page shows it.

2

Open a terminal in the folder and run:

node --env-file=.env ativo-api.js consent

--env-file=.env tells Node.js to load your settings; it is built in, nothing to install.

  1. The script prints a long URL. Open it in your browser.

  2. Atlassian asks you to choose your site and lists what the integration may read in Jira and in Ativo Programs. Click Accept.

  3. The browser tab shows "Consent received, you can close this tab."

  4. The terminal shows the granted scopes and "Consent done". A new file ativo-refresh-token.json now sits next to the script.

You do this once. Do it again only if the script was not used for 90 days, or if access was revoked.

3

Call the API

node --env-file=.env ativo-api.js

Each run gets fresh tokens, saves the new refresh token, and prints the data model version and your teams as JSON. Run it twice: the second run proves that the refresh token rotation works.

4

Make it yours

  • Another endpoint: pass the path, for example node --env-file=.env ativo-api.js /program. All paths are in Endpoints.

  • Your own logic: replace the console.log in main by what you need, for example writing a file or feeding another system. callApi returns the parsed JSON.

  • On a schedule: run the same command from Windows Task Scheduler or cron. Set the working folder to the script folder so that .env is found; the token file is always written next to the script. Run it at least once every 90 days, otherwise the consent of step 2 must be repeated.

If something goes wrong

Message
Meaning
What to do

Missing ATIVO_API_...

The setting is empty, or --env-file=.env was left out

Check the .env file and the command

EADDRINUSE ... 8080

Another program on your machine uses port 8080

Pick a free port: add ATIVO_API_CALLBACK_URL=http://localhost:8765/callback to .env and the same URL as callback URL in the Atlassian developer console

The Ativo scopes were not granted

The integration lacks the Ativo scopes

Add them under Permissions (Cloud setup step 2), consent again

No refresh token yet

The consent was never done in this folder

Run the consent command

Token request failed ... invalid_grant

The refresh token expired (90 days unused), was already used elsewhere, or access was revoked

Run the consent command again

API call failed: 403 ...

App REST APIs are off for the site, or a scope is missing

See the troubleshooting table of Cloud setup

Example script

How it maps onto the guide

Script
Guide

consentOnce builds the authorization URL, waitForCodeOnCallback receives the code

Step 3, points 2 and 3, without editing the URL or copying the code by hand

requestTokens with authorization_code

Step 3, point 4

refreshAccessToken and saveRefreshToken

Step 4, including the rule to keep the rotated token

callApi

Step 3, point 5, and every later call

For production use

  • Keep the client secret and the refresh token in your organisation's secret store rather than in files next to the script.

  • If several copies of the script can run at the same time, let only one of them refresh: each refresh token can be used once.

  • Check the data model version the script prints, and stop or warn when it changes, see Version.

Last updated