Skip to main content

Indent JavaScript Quickstart

Learn how to submit your first approval request using the Indent JavaScript SDK.


1. Install

Start by installing the Indent JavaScript SDK:

npm install @indent/approvals

# or for direct API usage
npm install @indent/api

2. Get your API Key

First, you'll need an Indent space and API token which you can find here:

Current User
Sign in to get API key
  • Can take actions on your behalf
  • Appears in audit log as you
Indent Space
Access Token
Note: this token is short lived and will expire soon

The INDENT_SPACE is the Indent account you want to use for requests and an INDENT_API_TOKEN which is used for authentication. There are two kinds of API tokens: short-lived user access tokens and long-lived service account tokens. Read more about API authentication.

3. Add await approval

Next, let's take a simple but sensitive workflow like user password reset. This workflow will be used to request approval for a user to reset their password.

import { approval } from '@indent/approvals'

async function resetPassword(userId, reason) {
await approval({
resources: [{
kind: 'action',
id: `reset-password:${userId}`,
displayName: `Reset Password (user:${userId})`

// by default, wait up to 10 seconds for approval
// 95% of approvals take less than 10 seconds

// -> do something to reset the user's password
console.log(`done: password reset user:${userId}`)

resetPassword(process.env.USER, process.env.REASON)

3. Try it for yourself

Once you run the script with node reset-password.js and you'll see the following output:

$ USER=123 REASON="to recover account" node reset-password.js

⏵ Requested approval #acmecorp/aec1b116-42b3-11ee-824e-42010aac000d
↳ Waiting for approval... (2s elapsed)
↳ Waiting for approval... (4s elapsed)
↳ Waiting for approval... (8s elapsed)
✅ Granted

done: password reset user:123

Here's a basic ready-to-go example on Stackblitz:

Remember that your API key is a secret!

Do not share it with others or expose it in any client-side code (browsers, native apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service

4. Use the full Indent API

If you have the @indent/approvals package installed, the @indent/api is implicitly installed. You can also install it separately to use the full Indent API to list resources, create petitions, and more.

npm install @indent/api

Here's an example of how to use the JavaScript bindings to list resources and create a petition:

import { IndentAPI } from '@indent/api'

// using INDENT_SPACE and INDENT_API_TOKEN from env vars
const indent = new IndentAPI({
spaceName: 'acmecorp', // defaults to process.env["INDENT_SPACE"]
apiToken: '*****' // defaults to process.env["INDENT_API_TOKEN"]

const resources = await indent.resource.list({
view: 'requestable'

const pet = await indent.petition.create({
reason: 'to debug production',
resources: [resources.find(r => r.displayName === 'Production')]

$ node request-prod.js