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.
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/1No quotes, no spaces around =. Copy the base URL exactly as the admin page shows it.
Consent, once
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.
The script prints a long URL. Open it in your browser.
Atlassian asks you to choose your site and lists what the integration may read in Jira and in Ativo Programs. Click Accept.
The browser tab shows "Consent received, you can close this tab."
The terminal shows the granted scopes and "Consent done". A new file
ativo-refresh-token.jsonnow 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.
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.loginmainby what you need, for example writing a file or feeding another system.callApireturns 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
.envis 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
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
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