Rudder API (11)

Download OpenAPI specification:Download

Rudder developers: dev@rudder.io URL: https://www.rudder.io License: CC-BY-SA 2.0

Introduction

Rudder exposes a REST API, enabling the user to interact with Rudder without using the webapp, for example in scripts or cronjobs.

Versioning

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:

  • the URL: each URL is prefixed by its version id, like /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
  • the HTTP headers. You can add the X-API-Version header to your request. The value needs to be an integer or 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.

Existing 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 Node key management

Response format

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...)

HTTP method

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, ...)

Parameters

To use Rudder API, you may need to pass data attributes to the API. Most of them depends on the called function and will be described below, in the corresponding function's section. Some are common to almost all functions and are described here:

Passing parameters

Parameters to the API can be sent:

  • As part of the URL

  • As request arguments

  • Directly in JSON format

As part of the URL

Parameters in URLs are used to indicate which data you want to interact with. The function will not work if this data is missing.

# Get the Rule of ID "id"
curl -H "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/rules/id

Request parameters

In most cases, data will be sent using request parameters. for all data you want to change, you need to pass one parameter.

Parameters follow the following schema:

key=value

You can pass parameters by two means:

  • As query parameters: At the end of your url, put a ? then your first parameter and then a & before next parameters
# 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"
  • As request data: You can pass those parameters in the request data, they won't figure in the URL, making it lighter to read, You can pass a file that contains data.
# 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

Directly in JSON format

Instead of passing parameters one by one, you can instead supply a JSON object containing all you want to do. You'll also have to set the Content-Type header to application/json (without it the JSON content would be ignored).

The supplied file must contain a valid JSON: strings need quotes, booleans and integers don't, ...

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 some parameters cannot be passed in a JSON (general parameters, it will be precised when necessary), 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"

General parameters

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.

Available for all requests

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: false

Available for modification requests (PUT/POST/DELETE)

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: A default string for each function

changeRequestDescription string
optional
Set the change request description, is used only if workflows are enabled.

Default value: ""

Authentication

API tokens

Authenticating against the API is mandatory for every request, as sensitive information like inventories or configuration rules may get exposed. It is done using a dedicated API Account, than can be created in the web interface on the 'API Accounts' page located inside the Administration part.

API Tokens settings

API Accounts are not linked to standard user accounts, and currently give full administrative privileges: they must be secured adequately. Once you have created an API account, you get a token that will be needed to authenticate every request. This token is the API equivalent of a password, and must be secured just like a password would be.

On any call to the API, you will need to add a X-API-Token header to your request to authenticate:

curl --request GET --header "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/rules

If you perform any action (creation, update, deletion) using the API, the event log generated will record the API account as the user.

Security Scheme Type API Key
Header parameter name: X-API-Token

Compliance

Access compliance data

Global compliance

get/compliance

Rudder server

/rudder/api/latest/compliance

Get current global compliance of a Rudder server

Authorizations:

Responses

200

Success

Response Schema: application/json
result
required
string
Enum: "success" "error"

Result of the request

action
required
string
Value: "getGlobalCompliance"

The id of the action

data
required
object

Request samples

Copy
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/compliance?prettify=true'

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result": "success",
  • "action": "getGlobalCompliance",
  • "data":
    {
    }
}

Compliance details for all nodes

get/compliance/nodes

Rudder server

/rudder/api/latest/compliance/nodes

Get current compliance of all the nodes of a Rudder server

Authorizations:
query Parameters
level
integer
Default: 10
Example: level=4

Number of depth level of compliance objects to display (1:rules, 2:directives, 3:components, 4:nodes, 5:values, 6:reports)

Responses

200

Success

Response Schema: application/json
result
required
string
Enum: "success" "error"

Result of the request

action
required
string
Value: "getNodesCompliance"

The id of the action

data
required
object

Request samples

Copy
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/compliance/nodes?level=2'

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result": "success",
  • "action": "getNodesCompliance",
  • "data":
    {
    }
}

Compliance details by node

get/compliance/nodes/{nodeId}

Rudder server

/rudder/api/latest/compliance/nodes/{nodeId}

Get current compliance of a node of a Rudder server

Authorizations:
path Parameters
nodeId
required
string <uuid (or "root")>
Example: 9a1773c9-0889-40b6-be89-f6504443ac1b

Id of the target node

query Parameters
level
integer
Default: 10
Example: level=4

Number of depth level of compliance objects to display (1:rules, 2:directives, 3:components, 4:nodes, 5:values, 6:reports)

Responses

200

Success

Response Schema: application/json
result
required
string
Enum: "success" "error"

Result of the request

action
required
string
Value: "getNodeCompliance"

The id of the action

data
required
object

Request samples

Copy
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/compliance/nodes/root?level=1'

Response samples

Content type
application/json
Copy
Expand all Collapse all
{
  • "result": "success",
  • "action": "getNodeCompliance",
  • "data":
    {
    }
}

Compliance details for all rules

get/compliance/rules

Rudder server

/rudder/api/latest/compliance/rules

Get current compliance of all the rules of a Rudder server