Skip to main content

Use the Permit API and SDK

Connect your application to Permit with the API and SDK: get an API key, install and initialize the SDK, and make your first API call.


Our API & SDK Reference

The API reference documents every endpoint.

1

Obtain your API key

Your application authenticates with Permit.io using an environment API key.

  1. Open the Permit Dashboard and go to the Projects screen.
  2. Select the desired Project and Environment.
  3. On the environment card, click the three dots icon in the top-right corner.
  4. Choose Copy API Key from the dropdown menu.
Copy secret key from user menu
TOP TIP

You can also copy the API key of the active environment from User Menu Icon > Copy Environment Key.

Copy secret key from Projects management
Remember

The API key you copy from the user menu belongs to the active environment in the sidebar. If you switch the active environment and click Copy Environment Key again, you copy a different API key: the key of the newly active environment.

2

Installing the SDK

Install the Permit SDK in your project. In your terminal, run:

No files found in the specified folder path.
3

Importing the Permit SDK

Import the Permit SDK. The library wraps the Permit API and the permission checks.

No files found in the specified folder path.
4

Initializing the Permit object

Initialize the Permit object, your main interface to Permit.

Pass the API key you copied from the Permit dashboard. The SDK uses it to authenticate with the Permit API.

No files found in the specified folder path.
tip

To make the SDK emit logs, add this to your Permit instance:

log: {
level: "debug";
}

To make the SDK throw errors on a timeout or network error, add this to your Permit instance:

throwOnError: true;
5

Get the project and environment id

Most API calls need your project ID and environment ID.

To get them, fetch the API Key Scope of your key:

No files found in the specified folder path.

The response looks like this:

No files found in the specified folder path.
6

Perform your first call to Permit

Make your first API call: create a role with permissions.

This example creates a Manager role with these permissions on an account resource:

  • Permission to read
  • Permission to delete
No files found in the specified folder path.

The result:

Manager Role

What did you learn?

In this guide, you've learned how to:

  • Fetch your API key.
  • Initialize a Permit Object using the permitio library.
  • Run your first API call and thus create a new role with permissions.

What's next? 🎉

  • Sync your first user into Permit
  • Create a new tenant
  • Learn about multi tenant authorization

Nice work! Onto the next one.