Skip to main content

Indent Bun Quickstart

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

Prerequisites

1. Install

Start by installing the Indent JavaScript SDK:

bun install @indent/approvals

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

2. Get your API Key

First, you'll need an Indent space and API token which you can find here: indent.com/api-keys

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
.env
INDENT_SPACE=
INDENT_API_TOKEN=************************************************************************************

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.

reset.ts
import { approval } from '@indent/approvals'

async function resetPassword(userId: string, reason: string) {
await approval({
reason,
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" bun run reset-password.ts

⏵ 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

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.

bun install @indent/api

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

request-prod.js
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')]
})

console.log(`Requested: indent.com/access/${pet.spaceName}/${pet.name}`)
$ bun run request-prod.ts

Requested: indent.com/access/example/aec1b116-42b3-11ee-824e-42010aac000d