Introduction

The BrandLeaf CRM API supports HTTP/1 and HTTP/2. We recommend using SSL. All endpoints are available at https://{tenant}.brandleaf.ai/api and generally follow REST principles.

Content Type

Send all requests as JSON and include the Content-Type: application/json header. Most responses, including errors, are also returned as JSON.

Authentication

Include your API token in the Authorization header: Authorization: Bearer {token}.

If authentication fails, the API returns status code 401.

Any user with API access enabled can generate an API token. Requests made with that token are treated as actions performed by that user in the dashboard.

To generate an API token, log in to the BrandLeaf CRM dashboard, open the profile dropdown in the sidebar, and select Personal Access Tokens.

Headers

With each API request, the following headers must be included:

Accept: application/json
Content-Type: application/json
Authorization: Bearer [API-TOKEN]

Some services and plugins automatically include the referer or origin header in API requests. Ensure that neither header is included, as they conflict with the Laravel Sanctum package used by BrandLeaf CRM.

Laravel Sanctum checks the referer and origin headers to determine whether a request came from the frontend and to validate the CSRF token. If either header is included, you will receive a CSRF token mismatch error.

Common HTTP Verbs

Verb Description
Used for retrieving resources.
Used for creating resources.
Used for updating resources.
Used for deleting resources.

Pagination

Requests that return multiple items are paginated, with 15 items per page by default. Use the ?page query parameter to retrieve another page. For some resources, you can set a custom page size of up to 100 using ?per_page. For technical reasons, not all endpoints support the ?per_page parameter.

Rate Limiting

The API limits the number of requests you can make within a given period. Limits vary and are provided in the following response header:

Header Name Description
X-RateLimit-Limit The maximum number of requests you're permitted to make per minute.
X-RateLimit-Remaining The number of requests remaining in the current rate limit window.

If you exceed the rate limit, the API returns a 429 Too Many Requests response.

Custom Fields

This section explains how to use custom fields with the BrandLeaf CRM API. To populate custom fields, send HTTP or requests.

When saving custom fields on resources, you will need to use the custom field ID you provided during its creation. The ID should be added in the HTTP request payload with the appropriate value based on the custom field type.

The examples below show how to provide custom field keys and values in a request.

Type Value Type Sample Payload
Boolean boolean [ ...payload, "field_id" => true ]
ColorSwatch string [ ...payload, "field_id" => '#333333' ]
Checkbox array [ ...payload, "field_id" => [5] // option IDs ]
Date date [ ...payload, "field_id" => "2020-11-26" ]
DateTime date UTC [ ...payload, "field_id" => "2020-11-26 06:00:00" ]
Email string [ ...payload, 'field_id' => "john@brandleaf.ai" ]
MultiSelect array [ ...payload, "field_id" => [5] // option IDs ]
Number integer [ ...payload, "field_id" => 200 ]
Numeric decimal(15, 3) [ ...payload, "field_id" => 1250.330 ]

[ ...payload, "field_id" => 1300 ]
Radio integer [ ...payload, "field_id" => 5 // option id ]
URL string [ ...payload, "field_id" => 'https://www.brandleafcrm.com' ]
Select integer [ ...payload, "field_id" => 10 // option id ]
Text string [ ...payload, "field_id" => "Sample Text" ]
Textarea string [ ...payload, "field_id" => "Sample Text" ]
Timezone string [ ...payload, "field_id" => "America/Toronto" ]

Troubleshoot

CSRF token mismatch

If you receive a CSRF token mismatch error when making an API request, check the following:

  • Ensure that the Accept header is sent with the request.
  • Ensure that the Authorization header is sent with the request.
  • Ensure that the referer and origin headers are NOT sent with the request.