Authentication

How does Asaas identify who you are?

Authenticate your API requests

The Asaas API uses an API key to identify the account responsible for the request.

Send the key in the access_token header. If it is missing, invalid, or does not belong to the environment being used, the API will return 401 Unauthorized.

📘

By the end of this guide, you will know how to configure the headers, choose the correct environment, and identify the main authentication errors.

Before you start

Create an API key in the environment you will use.

Keeping the key secure is your application's responsibility. Store it securely and consider restricting the authorized IPs.

Also see the additional security mechanisms.

⚠️

Never expose your API key in public code, frontend applications, images, logs, or repositories.

Configure the headers

Send the following headers:

{
  "Content-Type": "application/json",
  "User-Agent": "your_application_name",
  "access_token": "your_api_key"
}

HeaderUsage
access_tokenThe account's API key. Required in all authenticated requests.
User-AgentIdentifies the application responsible for the request.
Content-TypeUse application/json in requests that send a JSON body.
🚧

Sending the User-Agent

The User-Agent header is required for new root accounts created on or after 06/13/2024.

Use a value that identifies your application, especially when your framework does not set this header automatically.

See How to set the User-Agent.

Choose the environment

Use the URL that matches your API key's environment:

EnvironmentBase URL
Sandboxhttps://api-sandbox.asaas.com/v3
Productionhttps://api.asaas.com/v3
📘

Sandbox and Production API keys are different.

When changing the environment, also update the key used in the access_token header.

Test the endpoints in this documentation

❗️

Use a Sandbox key

Tests run directly from the API reference use the Sandbox environment.

To test the endpoints, create a Sandbox account and use the API key from that environment.

A Production key will return 401 Unauthorized.

Learn more about the Sandbox.

During development, use fictitious data and validate your integration in the Sandbox before switching the URL and the key to Production.

TLS security requirements

The Asaas API accepts connections using TLS 1.2 and TLS 1.3.

We recommend using TLS 1.3 whenever it is supported.

Authentication errors

A 401 Unauthorized response indicates that the request could not be authenticated.

Key used in the wrong environment

{
  "errors": [
    {
      "code": "invalid_environment",
      "description": "The provided API key does not belong to this environment"
    }
  ]
}

How to fix it: confirm that the URL and the key belong to the same environment.

  • Production: key starting with $aact_prod_
  • Sandbox: key starting with $aact_hmlg_

Missing authentication header

{
  "errors": [
    {
      "code": "access_token_not_found",
      "description": "The 'access_token' authentication header is required and was not found in the request"
    }
  ]
}

How to fix it: send the access_token header in all authenticated requests.

Incorrect key format

{
  "errors": [
    {
      "code": "invalid_access_token_format",
      "description": "The provided value does not appear to be a valid Asaas API key. Check your key's format"
    }
  ]
}

How to fix it: check whether the key contains spaces or extra characters, or was copied incompletely.

Invalid or revoked key

{
  "errors": [
    {
      "code": "invalid_access_token",
      "description": "The provided API key is invalid"
    }
  ]
}

How to fix it: confirm that the key is correct and has not been disabled, expired, or deleted.

Next steps



Did this page help you?