Transformations API
API Specification to manage your RudderStack Transformations and Libraries.
RudderStack's Transformations API allows you to create, read, update and delete transformations and libraries programmatically by making HTTP calls.
This guide describes the various API operations, related request and response structures, and error codes associated with this API.
Basic Authentication
The Transformations API is authenticated via HTTP Basic Authentication.
You can authenticate your account when using the API by including your email address in the username field and the secret access token in the password field in Authorization, if you're using POSTMAN.
You need to generate a personal access token to make any API calls. For more information, refer to the Personal Access Tokens guide.
Any API requests without the authentication will fail.
You can also pass your access token in the authorization headers, as shown:
The basic auth contains three parts:
Basic
Base64Encoded (Token)
Token =
emailaddress
+colon
+access token
Some examples are as shown:
Email Address:
myemailaddressis@gmail.com
Access Token -
1pHxUIA3jmxS2ip01zY696F80j7
Headers -
Basic {Base64Encoded(myemailaddressis@gmail.com:1pHxUIA3jmxS2ip01zY696F80j7)}
To make a successful request all of the upcoming endpoints should include this header.
Transformations
RudderStack transformations are responsible for converting the received event data into a suitable destination-specific format. All the transformation codes are written in JavaScript.
We also support user-specific transformations for real-time operations, such as aggregation and sampling.
Transformations help you to create a user-defined code that allow you to route your events in a manner that is suitable for your destinations.
Transformer payload
Field
Type
Presence
Description
name
String
Required
Sets the name of Transformer
description
String
Optional
Gives a description for a transformer
code
String
Optional
User-defined code that maps event data to destinations as defined by the user
codeVersion
String
Optional
This is an integer data always set to version 1 for API calls.
createdAt
Date
Optional
The timestamp of the transformer when it is created
updatedAt
Date
Optional
The timestamp of the transformer when it is updated
versionId
String
Optional
Maintains a version of transformer every time it is updated
workspaceId
Object
Optional
Workspace ID on which this transformation is created
destinations
Array
Optional
List of all Destination IDs to which your transformation is connected
POST
Create a transformation
https://api.rudderstack.com/transformationsCreates a transformation and get its object as response. Request ResponseQuery Parameterspublish optionalboolean
By default this flag is false
. It publishes your transformer to the latest version if set to true
and its code is made live for incoming traffic.Body Parametersevents optionalobject
Pass a set of JSON events to be tested for your code. This should be an array of JSON data.destinationIds optionalarray
Pass an array of destinationIds
that you wish to connect with this transformation. You can connect only if publish is set to true
.name requiredstring
Name of transformer that you wish to create.description optionalstring
Description of transformer goes here.code requiredstring
Code of transformer goes here.200: OKWhen publish is false we create a transformation revisions and you cannot connect a destination.
Events Parameters : Passing events in our API accepts a JSON format.
Creating a transformation can be done in one of the two ways:
publish: true
- In this case, we maintain two copies of the transformer. Among these, one is published and other is used for revisions. With the published version, you can connect a destination and its code is made live for incoming traffic.
publish: false
- In this case, we only create revisions for the transformation, which means you cannot connect any destinations to it. It cannot be used for any incoming event traffic. However, if you wish to publish some revisions of transformations you can do so using our Publish API.
We will be using these two terms Published and Revisions for transformations and libraries throughout our docs.
An example is as shown:
Curl Httpie
GET
List all the transformations
https://api.rudderstack.com/transformationsGet all published transformations for a workspace. Request Response200: OKThis will give an array of published transformations.
Curl Httpie
GET
Retrieve a single transformation
https://api.rudderstack.comtransformations/{id}Retrieve the published transformations from an ID. Request Response200: OKThis will give a transformation object on basis of the ID.
Curl Httpie
POST
Update a transformation
https://api.rudderstack.com/transformations/{id}Updating a transformation creates a new revision and sets it as published if the publish
flag is set is true
, and its code becomes live for upcoming traffic. If the publish
flag is false
, it only creates a new revision for that transformation. Request ResponseQuery Parameterspublish optionalboolean
By default this flag is false
. It publishes your transformer to the latest version if set to true
and its code is made live for incoming traffic.Body Parametersevents optionalobject
Pass a set of JSON events to be tested for your code.code optionalstring
Update the code of an existing transformation..description optionalstring
Update the description of a transformation.200: OKThis will update transformation object on basis of id.
An example request is as shown:
Curl Httpie
DELETE
Delete a transformation
https://api.rudderstack.com/transformations/{id}Delete a published transformations by ID. Note that RudderStack never deletes a transformation revisions. An example request and response is as shown: Request Response200: OK
Curl Httpie
GET
List all transformation versions
https://api.rudderstack.com/transformations/{id}/versionsGet all your transformation revisions by passing an ID. Request ResponseQuery Parameterscount optionalnumber
Gets the number of objects in your array. By default it always returns the first 5 objects.orderBy optionalstring
You can pass it either as ASC
for ascending or DESC
as descending. By default, it sets the order as ascending on createdAt
.200: OKThis gets an array of transformations revisions.
An example request is as shown:
Curl Httpie
GET
Retrieve a single transformation version
https://api.rudderstack.com/transformations/{id}/versions/{versionId}Get a single transformation revision. Request Response200: OKThis gets a single transformation version.
Curl Httpie
Libraries
Libraries are JavaScript codes that you can write and export to be used in your transformations. They give you the flexibility for reusing and maintaining different versions of the transformation code.
Suppose you write an aggregation function. You can easily export them and use it within different transformations just by importing that module by the library name.
Libraries payload
Field
Type
Presence
Description
name
String
Required
Sets the name of Library. This name is used as modules when it is imported in the transformation code.
description
String
Optional
Gives a description for a library.
code
String
Optional
User-defined code.
importName
String
Optional
This is library name that users can use in their transformation code while importing that library.
createdAt
Date
Optional
The timestamp when the transformer is created.
updatedAt
Date
Optional
The timestamp when the transformer is updated.
versionId
String
Optional
Maintains a version of library every time it is updated.
workspace
Object
Optional
Dictionary of information that provides workspace data where any transformation is used.
GET
Create a library
https://api.rudderstack.com/librariesCreate a library and get its object as a response. Request ResponseQuery Parameterspublish optionalboolean
By default this flag is false
. It publishes your library to the latest version if set to true
.Body Parametersname requiredstring
Name of library that you wish to createcode requiredstring
Code of library goes here.description optionalstring
Description of the library goes here200: OK
The publish
flag for a library works in the same way as for destinations.
Curl Httpie
GET
List all libraries
https://api.rudderstack.com/librariesGet all the published libraries. Request Response200: OKThis gets a single transformation version.
Curl Httpie
GET
Retrieve a library
https://api.rudderstack.com/libraries/{id}Get a single published library by ID. Request Response200: OKThis gets a single transformation version.
Curl Httpie
Updating a library with publish has same flow as for transformations.
A sample request is as shown:
Curl Httpie
GET
List all library versions
https://api.rudderstack.com/libraries/{id}/versions
Get all the library revisions for an ID.
Request ResponseQuery Parameterscount optionalnumber
By passing count it gets number of object in your array. By default it always returns first 5orderBy optionalstring
You can pass it either as ASC to get an ascending order or DESC for descending. By default it returns the ascending order on createdAt.
200: OK
Curl Httpie
GET
Retrieve a single library version
https://api.rudderstack.com/libraries/{id}/versions/{versionId}Get a single library revision. Request Response200: OK
Curl Httpie
Publish the API
As an end user you can create a transformer/library and perform several edits on it. Note that publishing is optional at create
.
If you perform some edits on this version of transformer, RudderStack takes your latest update as the published version, creates a copy of the older version, and saves it as revisions. Let's assume that after creating some 7 to 8 such revisions of your transformer, you finally decide to use the second or third version of the transformer.
This is where the RudderStack Publish API comes into play.
Publish payload
Field
Type
Presence
Description
transformations
Array
Optional
Pass an array of transformer versionIds
that you wish to publish.
libraries
Array
Optional
Pass an array of library versionIds
you wish to publish.
Any one of above payload must be present to make a successful publish
call.
POST
Publish a transformation or library
https://api.rudderstack.com/transformations/libraries/publishPublish any transformation revisions or library revisions. Request ResponseBody ParametersversionId requiredstring
Transformation versionId
that needs to be published.testInput optionalstring
This is an array of JSON object in a string format.transformations optionalarray
An array of object with the property as versionId
and testInput
.libraries optionalarray
An array of object with property as versionId
.200: OKSends published as true if versions is successfully published.
The sample request is as shown:
Curl Httpie
A few things to note:
You can choose to publish some revisions transformer without the libraries.
You can choose to publish some revisions libraries without the transformers.
You can publish both library and transformation revisions.
Whenever you call the publish
API , we run tests in our server to make sure you won't save any transformation/libraries code that can lead to any exceptions. In case if your publish is failing, make sure to check your transformation code and the libraries that it is referring to.
Contact us
To know more about the Transformations API, please feel free to contact us. You can also start a conversation in our Slack community, and we will be happy to help you.
Last updated
Was this helpful?