Getting started with Indent API
Let's add approvals to a sensitive workflow in your application or internal admin tools. This quickstart will show you how to add approvals to password reset flows.
First, let's create a directory for the quickstart:
mkdir admin-tools
cd admin-tools
1. Install
This quickstart uses the JavaScript SDK:
npm install @indent/approvals
Alternatively, you can use Python or the REST API directly.
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.
import { approval } from '@indent/approvals'
async function resetPassword(userId, reason) {
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)
Configure the following environment variables:
INDENT_SPACE=acmecorp
INDENT_API_TOKEN=s38...65e # Copy from indent.com/api-keys
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: https://stackblitz.com/edit/indent-api-quickstart
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
Next steps
Congrats! You've added approvals to your application. Here are some next steps:
await approval
in JavaScriptawait approval
in Python- Add approvals to Next.js
- Add approvals to LangChain
Troubleshooting
Error: Request failed with status code 401
Double check that you've set the INDENT_API_TOKEN
environment variable correctly. You can find your API token here: indent.com/api-keys
Error: Request failed with status code 403
If the error contains the text JWT_TIME_CONSTRAINT_FAILURE
, this means the access token you're using has expired. You can find your API token here: indent.com/api-keys
Or use a service account token
Error: Request failed with status code 404
Double check that you've set the INDENT_SPACE
environment variable correctly. You can find your space ID here: indent.com/api-keys