Installation
The management API is available through the same@trigger.dev/sdk
package used in defining and triggering tasks. If you have already installed the package in your project, you can skip this step.
Usage
Allv3
functionality is provided through the @trigger.dev/sdk/v3
module. You can import the entire module or individual resources as needed.
Authentication
There are two methods of authenticating with the management API: using a secret key associated with a specific environment in a project (secretKey
), or using a personal access token (personalAccessToken
). Both methods should only be used in a backend server, as they provide full access to the project.
Support for client-side authentication is coming soon to v3 but is not available at the time of
writing.
runs.list
function can be called using either a secretKey
or a personalAccessToken
, but the projectRef
argument is required when using a personalAccessToken
:
View endpoint support
View endpoint support
Consult the following table to see which endpoints support each authentication method.
Endpoint | Secret key | Personal Access Token |
---|---|---|
task.trigger | ✅ | |
task.batchTrigger | ✅ | |
runs.list | ✅ | ✅ |
runs.retrieve | ✅ | |
runs.cancel | ✅ | |
runs.replay | ✅ | |
envvars.list | ✅ | ✅ |
envvars.retrieve | ✅ | ✅ |
envvars.upload | ✅ | ✅ |
envvars.create | ✅ | ✅ |
envvars.update | ✅ | ✅ |
envvars.del | ✅ | ✅ |
schedules.list | ✅ | |
schedules.create | ✅ | |
schedules.retrieve | ✅ | |
schedules.update | ✅ | |
schedules.activate | ✅ | |
schedules.deactivate | ✅ | |
schedules.del | ✅ |
Secret key
Secret key authentication scopes the API access to a specific environment in a project, and works with certain endpoints. You can read our API Keys guide for more information.Personal Access Token (PAT)
A PAT is a token associated with a specific user, and gives access to all the orgs, projects, and environments that the user has access to. You can identify a PAT by thetr_pat_
prefix. Because a PAT does not scope access to a specific environment, you must provide the projectRef
argument when using a PAT (and sometimes the environment as well).
For example, when uploading environment variables using a PAT, you must provide the projectRef
and environment
arguments:
Handling errors
When the SDK method is unable to connect to the API server, or the API server returns a non-successful response, the SDK will throw anApiError
that you can catch and handle:
Retries
The SDK will automatically retry requests that fail due to network errors or server errors. By default, the SDK will retry requests up to 3 times, with an exponential backoff delay between retries. You can customize the retry behavior by passing arequestOptions
option to the configure
function:
requestOptions
parameter as the last argument, which can be used to customize the request options. You can use this to disable retries for a specific request:
When running inside a task, the SDK ignores customized retry options for certain functions (e.g.,
task.trigger
, task.batchTrigger
), and uses retry settings optimized for task execution.Auto-pagination
All list endpoints in the management API support auto-pagination. You can usefor await … of
syntax to iterate through items across all pages:
list
method to get the next/previous page of results:
Advanced usage
Accessing raw HTTP responses
All API methods return aPromise
subclass ApiPromise
that includes helpers for accessing the underlying HTTP response: