Skip to content
Skip to main content

Manage IAM principals with the public API

Last updated:

Create a principal that can read one mailbox, issue its credential, and rotate that credential through the IAM API. For principal, permission, and resource-binding concepts, see Nylas IAM.

IAM management endpoints require an IAM credential whose active principal has an Organization resource binding and the required management permissions. Existing application API keys (including legacy API keys) and provider OAuth tokens can’t authorize these endpoints.

If you already have an active, unexpired IAM credential with these permissions, you can use it. Otherwise, create your first management credential in the Dashboard before making API requests.

Create a management credential in the Dashboard

Section titled “Create a management credential in the Dashboard”

In the Nylas Dashboard:

  1. Open your organization’s Nylas IAM page and create a principal with an Organization resource binding.
  2. Assign the IAM Admin system role (role_system_iam_admin).
  3. Open the Credentials tab and create a credential for that active principal. Choose an expiration and store the secret securely.
  4. Load the secret into your server as NYLAS_IAM_ADMIN_KEY. Keep it separate from the scoped key you create for your workload.

Send the credential’s secret as Authorization: Bearer <NYLAS_IAM_ADMIN_KEY>. Requests act within that credential’s organization.

Use https://api.us.nylas.com for the U.S. region or https://api.eu.nylas.com for the E.U. region. Use the same region as the application that owns a Grant, Workspace, or Application binding.

The IAM Admin role lets you manage principals and credentials. For read-only access, use IAM Auditor (role_system_iam_auditor). Both require an Organization resource binding.

For narrower automation, assign only the permissions you need through a custom role or direct assignments. Each operation in the principals and credentials references lists its required permission. Manage custom roles in the Dashboard.

Use your management credential for both creation requests. The workload will use the separate credential you create for it.

This example creates a mailbox reader bound to one grant. Set NYLAS_GRANT_ID to a grant in your organization. In the curl request, replace <NYLAS_GRANT_ID> in the JSON body with that ID.

Save the returned data.id as NYLAS_PRINCIPAL_ID. This principal has messages.read permission for the bound grant. For other bindings, roles, and field requirements, see Create IAM principal.

Set NYLAS_PRINCIPAL_ID to the principal ID returned above. Create an api_key credential with a 90-day lifetime:

Store data.secret in your secrets service immediately. Nylas returns it only once, so don’t log the response. Save data.id for rotation or revocation.

The credential inherits its principal’s access. For expiration requirements and response fields, see Create IAM credential.

Load the new secret as NYLAS_IAM_API_KEY in the workload’s server. It can now read messages from the bound grant:

curl --request GET \
--url "https://api.us.nylas.com/v3/grants/$NYLAS_GRANT_ID/messages" \
--header "Authorization: Bearer $NYLAS_IAM_API_KEY"

Keep the organization management key out of this workload. Provider OAuth scopes still constrain what Nylas can do with the connected account; IAM permissions don’t replace them.

Manage existing principals and credentials

Section titled “Manage existing principals and credentials”

Use the organization management credential for these operations. Changes to a principal affect all credentials attached to it.

List and paginate principals or credentials

Section titled “List and paginate principals or credentials”

Use List IAM principals or List IAM credentials. If the response includes next_cursor, pass it as page_token on the next request. Stop when next_cursor is absent. The references cover filters and page sizes.

Use Update IAM principal to change the workload’s access. Supplied fields replace their current values; omitted fields stay unchanged. For example, {"direct_permissions": ["messages.read"]} replaces the entire direct-permission set.

Disable a principal to stop all of its credentials from authenticating. Delete it only when you want to permanently remove the principal and every attached credential. See Delete IAM principal.

To rotate a key without downtime:

  1. Create a replacement credential on the same principal.
  2. Store and deploy the new secret.
  3. Verify the workload can make its intended requests.
  4. Delete the old credential.

To stop access immediately, disable the credential. Deleting a credential is permanent.

Understand principal and credential limits

Section titled “Understand principal and credential limits”

Reserve credential capacity for rotation so you can deploy a replacement before deleting the old credential. For quota formulas, counting rules, and examples, see the IAM principals reference.

For authentication or permission failures, check that your management credential is active and unexpired, its principal is active, and the principal has an Organization binding and the operation’s required permission. Use the response’s request_id to inspect IAM activity. Each operation’s reference lists its errors.

If credential creation times out, list the principal’s credentials before retrying. Nylas might have created a credential even if you didn’t receive its secret. Delete any unusable credential before creating a replacement.

To give an MCP agent access to this mailbox, load the workload credential’s secret as NYLAS_API_KEY and follow the MCP client setup instructions. Keep the management credential in your provisioning service.

Use the MCP endpoint for your application’s region and the bound grant ID. Verify that the agent can read messages. After rotation, load the replacement secret and restart the client before deleting the old credential.