Download OpenAPI specification: openapi.yml
Rudder exposes a REST API, enabling the user to interact with Rudder without using the webapp, for example in scripts or cronjobs.
Each time the API is extended with new features (new functions, new parameters, new responses, …), it will be assigned a new version number. This will allow you
to keep your existing scripts (based on previous behavior). Versions will always be integers (no 2.1 or 3.3, just 2, 3, 4, …) or latest
.
You can change the version of the API used by setting it either within the url or in a header:
/api/version/function
.# Version 10
curl -X GET -H "X-API-Token: yourToken" https://rudder.example.com/rudder/api/10/rules
# Latest
curl -X GET -H "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/rules
# Wrong (not an integer) => 404 not found
curl -X GET -H "X-API-Token: yourToken" https://rudder.example.com/rudder/api/3.14/rules
latest
.# Version 10
curl -X GET -H "X-API-Token: yourToken" -H "X-API-Version: 10" https://rudder.example.com/rudder/api/rules
# Wrong => Error response indicating which versions are available
curl -X GET -H "X-API-Token: yourToken" -H "X-API-Version: 3.14" https://rudder.example.com/rudder/api/rules
In the future, we may declare some versions as deprecated, in order to remove them in a later version of Rudder, but we will never remove any versions without warning, or without a safe period of time to allow migration from previous versions.
Version | Rudder versions it appeared in | Description |
---|---|---|
1 | Never released (for internal use only) | Experimental version |
2 to 10 (deprecated) | 4.3 and before | These versions provided the core set of API features for rules, directives, nodes global parameters, change requests and compliance, rudder settings and system API |
11 | 5.0 | New system API (replacing old localhost v1 api): status, maintenance operations and server behavior |
12 | 6.0 and 6.1 | Node key management |
13 | 6.2 |
|
14 | 7.0 |
|
15 | 7.1 |
|
16 | 7.2 |
|
All responses from the API are in the JSON format.
{
"action": "The name of the called function",
"id": "The ID of the element you want, if relevant",
"result": "The result of your action: success or error",
"data": "Only present if this is a success and depends on the function, it's usually a JSON object",
"errorDetails": "Only present if this is an error, it contains the error message"
}
Success responses are sent with the 200 HTTP (Success) code
Error responses are sent with a HTTP error code (mostly 5xx…)
Rudder’s REST API is based on the usage of HTTP methods. We use them to indicate what action will be done by the request. Currently, we use four of them:
GET: search or retrieve information (get rule details, get a group, …)
PUT: add new objects (create a directive, clone a Rule, …)
DELETE: remove objects (delete a node, delete a parameter, …)
POST: update existing objects (update a directive, reload a group, …)
Some parameters are available for almost all API functions. They will be described in this section. They must be part of the query and can’t be submitted in a JSON form.
Field | Type | Description |
---|---|---|
prettify | boolean optional | Determine if the answer should be prettified (human friendly) or not. We recommend using this for debugging purposes, but not for general script usage as this does add some unnecessary load on the server side. Default value: |
Field | Type | Description |
---|---|---|
reason | string optional or required | Set a message to explain the change. If you set the reason messages to be mandatory in the web interface, failing to supply this value will lead to an error. Default value: |
changeRequestName | string optional | Set the change request name, is used only if workflows are enabled. The default value depends on the function called Default value: |
changeRequestDescription | string optional | Set the change request description, is used only if workflows are enabled. Default value: |
Parameters to the API can be sent:
As part of the URL for resource identification
As data for POST/PUT requests
Directly in JSON format
As request arguments
Parameters in URLs are used to indicate which resource you want to interact with. The function will not work if this resource is missing.
# Get the Rule of ID "id"
curl -H "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/rules/id
CAUTION: To avoid surprising behavior, do not put a ‘/’ at the end of an URL: it would be interpreted as ‘/[empty string parameter]’ and redirected to ‘/index’, likely not what you wanted to do.
JSON format is the preferred way to interact with Rudder API for creating or updating resources.
You’ll also have to set the Content-Type header to application/json (without it the JSON content would be ignored).
In a curl
POST
request, that header can be provided with the -H
parameter:
curl -X POST -H "Content-Type: application/json" ...
The supplied file must contain a valid JSON: strings need quotes, booleans and integers don’t, etc.
The (human readable) format is:
{
"key1": "value1",
"key2": false,
"key3": 42
}
Here is an example with inlined data:
# Update the Rule 'id' with a new name, disabled, and setting it one directive
curl -X POST -H "X-API-Token: yourToken" -H "Content-Type: application/json"
https://rudder.example.com/rudder/api/rules/latest/{id}
-d '{ "displayName": "new name", "enabled": false, "directives": "directiveId"}'
You can also pass a supply the JSON in a file:
# Update the Rule 'id' with a new name, disabled, and setting it one directive
curl -X POST -H "X-API-Token: yourToken" -H "Content-Type: application/json" https://rudder.example.com/rudder/api/rules/latest/{id} -d @jsonParam
Note that the general parameters view in the previous chapter cannot be passed in a JSON, and you will need to pass them a URL parameters if you want them to be taken into account (you can’t mix JSON and request parameters):
# Update the Rule 'id' with a new name, disabled, and setting it one directive with reason message "Reason used"
curl -X POST -H "X-API-Token: yourToken" -H "Content-Type: application/json" "https://rudder.example.com/rudder/api/rules/latest/{id}?reason=Reason used" -d @jsonParam -d "reason=Reason ignored"
In some cases, when you have little, simple data to update, JSON can feel bloated. In such cases, you can use request parameters. You will need to pass one parameter for each data you want to change.
Parameters follow the following schema:
key=value
You can pass parameters by two means:
# Update the Rule 'id' with a new name, disabled, and setting it one directive
curl -X POST -H "X-API-Token: yourToken" https://rudder.example.com/rudder/api/rules/latest/{id}?"displayName=my new name"&"enabled=false"&"directives=aDirectiveId"
# Update the Rule 'id' with a new name, disabled, and setting it one directive (in file directive-info.json)
curl -X POST -H "X-API-Token: yourToken"
https://rudder.example.com/rudder/api/rules/latest/{id} -d "displayName=my new name" -d "enabled=false" -d @directive-info.json
Use this page to mock Rudder API in your testing and development.
Run our mock API sample using the open source WireMock library, or in the free edition of WireMock Cloud. You'll have a working API server simulating the behavior of Rudder API, which will allow you to keep building and testing even if the actual API you isn't currently available.