API and integrations

Creating and revoking an API token

How to create a GPS tracking API token with an expiry date, send it as a bearer token from a script, keep its rights narrow with a dedicated user, and revoke it when the integration ends.

Ashish Srivastava4 min read

A developer at a standing desk in a quiet evening office holds a small brass key over a laptop turned away from the camera

A GPS tracking API token lets a script or an integration call the Alongpin API without a password. Create one in the portal under Settings → Your account → Password and two-factor, in the API tokens section: choose when it expires, select Create token and copy it straight away, because it is not shown again. Send it with every request as Authorization: Bearer <token>. The token acts as you, with exactly your rights, until it expires or you revoke it.

Key takeaways

  • A token lasts 7 days unless you choose a date, and at most one year.
  • It carries the rights of the user who made it: no more, no less.
  • There is no list of tokens, so note where you use each one.
  • Revoking a token stops it everywhere within moments; changing your password does not.

Create a token in the portal

  1. Open the account menu and choose Profile and settings, then Password and two-factor.
  2. In the API tokens section, set Expires. Without a change the token ends in 7 days; you can pick any day within the next year.
  3. Select Create token. The portal confirms the date the token is valid until and reminds you to copy it now.
  4. Use Copy the new token and store it where your script keeps its secrets: an environment variable or a secret store, never in the code itself.
The Password and two-factor settings with the API tokens section: an expiry date, the Create token button and Revoke a token
API tokens are made under Settings → Your account → Password and two-factor.

The portal keeps no list of the tokens you made, which is why the token is shown only once. Write down where each one is used, so you know what to revoke later.

Create a token through the API

A script can make its own token from a signed-in session. Sign in with POST /api/session, then ask for a token with an optional expiration (an ISO-8601 instant, in the future and within one year):

curl -s -c cookies.txt -d 'email=you@example.com&password=YOUR_PASSWORD' \
  https://YOUR_HOST/api/session > /dev/null
TOKEN=$(curl -s -b cookies.txt -X POST https://YOUR_HOST/api/session/token \
  -d 'expiration=2027-03-31T00:00:00Z')

The answer is the token as plain text. Accounts with two-factor sign-in send the one-time code with the password. A token made from a session that did not start with a password (another token, a share link) cannot outlive that session, and ends when it is revoked.

Send it as a bearer token

Put the token in the Authorization header of each request:

curl -H "Authorization: Bearer $TOKEN" "https://YOUR_HOST/api/devices?limit=20"

On GET requests the token may also go in the address as ?token=, which helps for WebSockets and file downloads where a header cannot be set. Prefer the header elsewhere: addresses are easily copied into logs. The API reference lists every endpoint and the right each one needs.

The token sees what its user sees

Every call made with the token is checked against its user, at the moment of the call: the user's roles and their scope, the devices the user owns or has been shared, and the read-only flag. A read-only user makes a read-only token. When an administrator changes the user's rights, existing tokens follow at once.

Lists are filtered rather than refused: a token whose user may see no geofences gets an empty list. Asking for one object outside the user's reach answers 403.

Use a separate user with a narrow role for integrations

For anything that runs unattended, do not use your own account. Ask whoever manages Users and roles in your account to create a user for the integration, with a role that grants only what it needs, for example reading devices and positions of one group. Then sign in as that user and create the token there.

This keeps the integration's reach small if the token leaks, lets you revoke it without touching your own sign-in, and makes the integration's changes show as its own user in the audit log. The security overview explains how roles, tokens and the audit log fit together, and the developers overview has the other building blocks.

Revoke a token

  1. Under Password and two-factor, in API tokens, choose Revoke a token.
  2. Paste the token itself into Token; there is no list to pick it from.
  3. Select Revoke token.
The Revoke a token dialog with a field to paste the token and the Revoke token button
There is no list of tokens: paste the token itself to revoke it.

The token stops working everywhere within moments, and live connections opened with it are closed. You can revoke your own tokens and those of users you manage; administrators can revoke any token. Read-only accounts can revoke only their own.

From a script, send the token to POST /api/session/token/revoke as the form field token; the answer is 204.

Frequently asked questions

How long can a token last?

Seven days by default and at most one year. Choose the shortest period that suits the job, and create a new token before the old one ends.

Does changing my password end my tokens?

No. Other sessions and tokens keep working after a password change. If a token may have leaked, revoke it.

Can I see which tokens I have created?

No. Tokens are shown once, when they are made; their creation is recorded in the audit log, but there is no list to read them back from.

API and integrations

Downloading reports through the API

How to run the same reports as the portal from a script and receive JSON, CSV or Excel, with devices, groups and the period as parameters, the time zone and units of the token’s user, and long periods split into pieces.

Ashish Srivastava4 min read

Put your first device on the map today

Book a demo if you would rather see it with your own use case first. Choose a package in the portal; you see the first invoice before you confirm.

Chat with us