To access Daftra's API securely, every request must be authorized. Daftra supports two authorization methods to accommodate different use cases:
Method 1: Using API Key#
This is the simplest way to authorize requests. You can generate and use an API key directly from your Daftra account.When using API Key Authentication, make sure to unmark the "Authorization (access token)" header in your API request. Even with a correct API key, leaving it enabled will cause an authentication error. Steps to Get Your API Key:#
1.
Log in to your Daftra account
2.
Navigate to: Settings → API → API Key
3.
Generate or copy your existing API Key
4.
Include it in the header of each request using the format:
Important: Keep your API Key secure. Do not expose it in public repositories or client-side code.
API Key Roles (Entity Access Control)#
API Key Roles let you restrict what an API key can access. Instead of giving a key full access to every entity in your account, you can define exactly which entities (such as invoice or client) the key is allowed or forbidden to work with.Each API key can have one role type:| Role Type | Behavior |
|---|
| Only Allow | The key can access only the listed entities. All others are refused. |
| Only Block | The key can access all entities except the listed ones. |
Example 1: Only Allow#
| Setting | Value |
|---|
| Role Type | Only Allow |
| Entities | invoice, client |
✅ Requests to invoice and client endpoints are accepted.
❌ Requests to any other entity (e.g. product, supplier, purchase_invoice) are refused.
Use this when an integration needs access to a small, specific set of data, such as a billing system that only reads invoices and clients.Example 2: Only Block#
| Setting | Value |
|---|
| Role Type | Only Block |
| Entities | supplier, purchase_invoice |
✅ Requests to every entity are accepted except supplier and purchase_invoice.
❌ Requests to supplier and purchase_invoice endpoints are refused.
Use this when a key needs broad access but must be kept away from sensitive areas.1.
Log in to your Daftra account
2.
Navigate to: Settings → API → API Key
3.
Open the API key you want to restrict
4.
In the Roles section, choose the role type: Only Allow or Only Block
5.
Add the entity names (e.g. invoice, client)
6.
Save your changes. The rules apply immediately to all requests made with this key
Refused Requests#
If a request targets an entity that the key's role does not permit, the API rejects it with 403 Forbidden, even when the API key itself is valid.Roles apply to API Key authentication only (Method 1). They restrict which entities the key can reach. They do not grant access beyond the account's own permissions.
Method 2: Token-Based Authentication (OAuth 2.0)#
This method is recommended for integrations requiring dynamic access, such as third-party applications connecting on behalf of users.How It Works:#
1.
Request an access token using your credentials or through an authorization grant
2.
Use the token in your API requests