LogoLogo
  • Contributing to RudderStack
  • Destination_Name
  • LICENSE
  • RudderStack Docs
  • docs
    • FAQ
    • Identity Resolution
    • Home
    • cloud-extract-sources
      • ActiveCampaign Source
      • Bing Ads
      • Chargebee
      • Common Settings
      • Facebook Ads
      • Freshdesk
      • Google Ads Source
      • Google Analytics
      • Google Search Console
      • Google Sheets
      • Cloud Extract Sources
      • Intercom v2
      • Intercom
      • Mailchimp
      • Marketo
      • Mixpanel
      • NetSuite
      • Pipedrive
      • QuickBooks
      • Salesforce Pardot
      • Sendgrid Source
      • Stripe Source
      • Xero
      • Zendesk Chat
      • Zendesk
      • hubspot
        • HubSpot Data Model and Schema Information
        • HubSpot
      • salesforce
        • Salesforce
        • Schema Comparison: RudderStack vs. Segment
    • connections
      • Connection Modes: Cloud Mode vs. Device Mode
    • data-governance
      • Data Governance
      • RudderTyper
      • Data Governance API
      • RudderTyper
      • tracking-plans
        • Tracking Plans
        • Tracking Plan Spreadsheet
    • data-warehouse-integrations
      • Amazon Redshift
      • Azure Data Lake
      • Azure Synapse
      • ClickHouse
      • Databricks Delta Lake
      • Google Cloud Storage Data Lake
      • Google BigQuery
      • Identity Resolution
      • Warehouse Destinations
      • Microsoft SQL Server
      • PostgreSQL
      • Amazon S3 Data Lake
      • Snowflake
      • FAQ
      • Warehouse Schema
    • destinations
      • Destinations
      • Webhooks
      • advertising
        • Bing Ads
        • Criteo
        • DCM Floodlight
        • Facebook App Events
        • Facebook Custom Audience
        • Facebook Pixel
        • Google Ads (gtag.js)
        • Google AdWords Enhanced Conversions
        • Google Adwords Remarketing Lists (Customer Match)
        • Advertising
        • LinkedIn Insight Tag
        • Lotame
        • Pinterest Tag
        • Reddit Pixel
        • Snap Pixel
        • TikTok Ads
      • analytics
        • Amplitude
        • AWS Personalize
        • Chartbeat
        • Firebase
        • FullStory
        • Google Analytics 360
        • Google Analytics
        • Heap.io
        • Hotjar
        • Analytics
        • Indicative
        • Keen
        • Kissmetrics
        • Kubit
        • Lytics
        • Mixpanel
        • Pendo
        • PostHog
        • Quantum Metric
        • Singular
        • adobe-analytics
          • Adobe Analytics Heartbeat Measurement
          • Mobile Device Mode Settings
          • Web Device Mode Settings
          • E-commerce Events
          • Adobe Analytics
          • Setting Up Adobe Analytics in RudderStack
        • google-analytics-4
          • Cloud Mode
          • Device Mode
          • Google Analytics 4
          • Setting up Google Analytics 4
        • profitwell
          • ProfitWell
          • Cloud Mode
          • Device Mode
      • attribution
        • Adjust
        • AppsFlyer
        • Branch
        • Attribution
        • Kochava
        • TVSquared
      • business-messaging
        • Business Messaging
        • Intercom
        • Kustomer
        • Slack
        • Trengo
      • continuous-integration
        • Visual Studio App Center
        • Continuous Integration
      • crm
        • Delighted
        • HubSpot
        • CRM
        • Salesforce
        • Variance
        • Zendesk
      • customer-data-platform
        • Customer Data Platform
        • Segment
      • error-reporting
        • Bugsnag
        • Error Reporting
        • Sentry
      • marketing
        • ActiveCampaign
        • AdRoll
        • Airship
        • Appcues
        • Autopilot
        • Blueshift
        • Braze
        • CleverTap
        • Customer.io
        • Gainsight PX
        • Gainsight
        • Marketing
        • Iterable
        • Klaviyo
        • Leanplum
        • Mailchimp
        • Marketo Lead Import
        • Marketo
        • MoEngage
        • Ometria
        • Pardot
        • Post Affiliate Pro
        • Qualtrics
        • SendGrid
        • Salesforce Marketing Cloud
        • Userlist
        • drip
          • Cloud Mode
          • Device Mode
          • Drip
          • Setting Up Drip in RudderStack
      • productivity
        • Google Sheets
        • Productivity
      • storage-platforms
        • Amazon S3
        • DigitalOcean Spaces
        • Google Cloud Storage
        • Storage Platforms
        • Azure Blob Storage
        • MinIO
        • Redis
      • streaming-platforms
        • Amazon EventBridge
        • Amazon Kinesis Firehose
        • Amazon Kinesis
        • Azure Event Hubs
        • BigQuery Stream
        • Confluent Cloud
        • Google Pub/Sub
        • Streaming Platforms
        • Apache Kafka
      • tag-managers
        • Google Tag Manager
        • Tag Managers
      • testing-and-personalization
        • Algolia Insights
        • Candu
        • Google Optimize
        • A/B Testing & Personalization
        • LaunchDarkly
        • Monetate
        • Optimizely Full Stack
        • Optimizely Web
        • Split.io
        • Statsig
        • VWO (Visual Website Optimizer)
    • get-started
      • RudderStack Cloud vs. RudderStack Open Source
      • Glossary
      • Get Started
      • RudderStack Architecture
    • reverse-etl
      • Amazon Redshift
      • Amazon S3
      • ClickHouse
      • FAQ
      • Google BigQuery
      • Reverse ETL
      • PostgreSQL
      • Snowflake
      • common-settings
        • Importing Data using Models
        • Importing Data using Tables
        • Common Settings
        • Sync Modes
        • Sync Schedule
      • features
        • Airflow Provider
        • Features
        • Models
        • Visual Data Mapper
    • rudderstack-api
      • Data Regulation API
      • HTTP API
      • RudderStack API
      • Personal Access Tokens
      • Pixel API
      • Test API
      • api-specification
        • Application Lifecycle Events Specification
        • API Specification
        • Video Events Specification
        • rudderstack-ecommerce-events-specification
          • Browsing
          • Coupons
          • E-Commerce Events Specification
          • Ordering
          • Promotions
          • Reviewing
          • Sharing
          • Wishlist
        • rudderstack-spec
          • Alias
          • Common Fields
          • Group
          • Identify
          • RudderStack Event Specification
          • Page
          • Screen
          • Track
    • rudderstack-cloud
      • Audit Logs
      • Dashboard Overview
      • Destinations
      • RudderStack Cloud
      • Live Events
      • Connection Modes: Cloud Mode vs. Device Mode
      • Sources
      • Teammates (User Management)
      • connections
        • Adding a Destination
        • Connections
    • rudderstack-open-source
      • Control Plane Setup
      • RudderStack Open Source
      • installing-and-setting-up-rudderstack
        • Developer Machine Setup
        • Docker
        • Data Plane Setup
        • Kubernetes
        • Sending Test Events
    • stream-sources
      • App Center
      • AppsFlyer
      • Auth0
      • Braze
      • Customer.io
      • Extole
      • Event Stream Sources
      • Iterable
      • Looker
      • PostHog
      • Segment
      • Shopify
      • Webhook Source
      • rudderstack-sdk-integration-guides
        • Client-side Event Filtering
        • SDKs
        • AMP Analytics
        • Cordova
        • .NET
        • Go
        • Java
        • Node.js
        • PHP
        • Python
        • React Native
        • Ruby
        • Rust
        • Unity
        • SDK FAQs
        • rudderstack-android-sdk
          • Adding Application Class
          • Flushing Events Periodically
          • Android
        • rudderstack-flutter-sdk
          • Flutter SDK v1
          • Flutter v2
          • Flutter
        • rudderstack-ios-sdk
          • iOS
          • tvOS
          • watchOS
        • rudderstack-javascript-sdk
          • Data Storage in Cookies
          • Detecting Ad-blocked Pages
          • JavaScript
          • JavaScript SDK Enhancements
          • JavaScript SDK FAQs
          • Querystring API
          • Quick Start Guide
          • Version Migration Guide
          • consent-managers
            • Consent Managers
            • OneTrust
    • transformations
      • Access Token
      • FAQ
      • Transformations
      • Transformations API
    • user-guides
      • User Guides
      • administrators-guide
        • Troubleshooting Guide
        • Alerting Guide
        • Bucket Configuration Settings for Event Backups
        • Configuration Parameters
        • Event Replay
        • High Availability
        • Horizontal Scaling
        • Administrator's Guides
        • Infrastructure Provisioning
        • Monitoring and Metrics
        • Okta SSO Setup
        • OneLogin SSO Setup
        • RudderStack Grafana Dashboard
        • Software Releases
      • how-to-guides
        • How to Use Custom Domains
        • How to Develop Integrations for RudderStack
        • How to Configure a Destination via the Event Payload
        • How to Filter Events using Different Methods
        • How to Filter Selective Destinations
        • How to Submit a Pull Request for a New Integration
        • How-to Guides
        • How to Debug Live Destination Events
        • How to Use AWS Lambda Functions with RudderStack
        • create-a-new-destination-transformer-for-rudder
          • Best Practices for Coding Transformation Functions in JavaScript
          • How to Create a New Destination Transformation for RudderStack
        • implement-native-js-sdk-integration
          • How to Add a Device Mode SDK to RudderStack JavaScript SDK
          • How to Implement a Native JavaScript SDK Integration
        • rudderstack-jamstack-integration
          • How to Integrate RudderStack with Your JAMstack Site
          • How to Integrate Rudderstack with Your Angular App
          • How to Integrate Rudderstack with Your Astro Site
          • How to Integrate Rudderstack with Your Eleventy Site
          • How to Integrate Rudderstack with Your Ember.js App
          • How to Integrate Rudderstack with a Gatsby Website
          • How to Integrate Rudderstack with a Hugo Site
          • How to Integrate Rudderstack with Your Jekyll Site
          • How to Integrate Rudderstack with Your Next.js App
          • How to Integrate Rudderstack with Your Nuxt.js App
          • How to Integrate Rudderstack with Your Svelte App
          • How to Integrate Rudderstack with Your Vue App
      • migration-guides
        • Migrating from Blendo to RudderStack
        • Migrating Your Warehouse Destination from Segment to RudderStack
        • Migration Guides
        • Migrating from Segment to RudderStack
  • src
    • @rocketseat
      • gatsby-theme-docs
        • text
          • Home
Powered by GitBook
On this page
  • Basic Authentication
  • Transformations
  • Create a transformation
  • List all the transformations
  • Retrieve a single transformation
  • Update a transformation
  • Delete a transformation
  • List all transformation versions
  • Retrieve a single transformation version
  • Libraries
  • Create a library
  • List all libraries
  • Retrieve a library
  • List all library versions
  • Publish the API
  • Contact us

Was this helpful?

  1. docs
  2. transformations

Transformations API

API Specification to manage your RudderStack Transformations and Libraries.

PreviousTransformationsNextuser-guides

Last updated 2 years ago

Was this helpful?

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

Any API requests without the authentication will fail.

You can also pass your access token in the authorization headers, as shown:

Authorisation: Basic {Base64Encoded(emailaddress:AccessToken)}

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.

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 optionalbooleanBy 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 optionalobjectPass a set of JSON events to be tested for your code. This should be an array of JSON data.destinationIds optionalarrayPass an array of destinationIds that you wish to connect with this transformation. You can connect only if publish is set to true.name requiredstringName of transformer that you wish to create.description optionalstringDescription of transformer goes here.code requiredstringCode of transformer goes here.200: OKWhen publish is false we create a transformation revisions and you cannot connect a destination.

publish = true ::
{
  "id": "1puvbvMW2mxWvfFFnPIv5TTv4wL",
  "versionId": "1puvbyk8adHTxWHYre4GwZbrMGL",
  "name": "Create Transformation Tested-4",
  "description": "Descriptrion 1",
  "code": "function transform(events) {return events;}",
  "codeVersion": "1",
  "createdAt": "2021-03-04T04:48:27.288Z",
  "updatedAt": "2021-03-04T04:48:27.288Z",
  "destinations": [
    {
      "id": "xdcfvgbvfcdvfgbhgvf",
      "name": "Destination 1",
      "enabled": true,
    }
  ]
}

publish = false ::
{
    "id": "1puu7XFWgbwObDY4nbJdF0cgeTC",
    "versionId": "1puu7e4DXYMPJrLglIICgFK75fD",
    "name": "new Transformation 3",
    "description": "Some Description",
    "code": "function transformEvent(events) { return events.context; } ",
    "createdAt": "2021-03-04T04:48:27.288Z",
    "updatedAt": "2021-03-04T04:48:27.288Z",
}

Events Parameters : Passing events in our API accepts a JSON format.

[
  {
    "anonymousId": "8d872292709c6fbe",
    "channel": "mobile",
    "context": {
      "traits": {
        "address": {
          "city": "Kolkata",
          "country": "India",
          "postalcode": "700096",
          "state": "West bengal",
          "street": "Park Street"
        }
      }
    },
    "properties": {
      "revenue": "30",
      "currency": "USD",
      "quantity": "5",
      "price": "58.0"
    }
  }
]

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

curl --location -X POST 'https://api.rudderstack.com/transformations' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
-d '{
    "name": "Create Transformation Tested-4",
    "code": "function transformEvent(events) { return events; } ",
    "description": "Descriptrion 1"
}'
http POST 'https://api.rudderstack.com/transformations' \
name='Create Transformation Tested-4' code='function transformEvent(events) { return events; }' description='Descriptrion 1' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

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.

{
  "transformations": [
    {
      "id": "sedrftg",
      "versionId": "edrtv",
      "name": "new Transformations-2",
      "description": "",
      "code": "function transformEvent(events) { return events; }",
      "codeVersion": "1",
      "createdAt": "2021-03-04T04:48:27.288Z",
      "updatedAt": "2021-03-04T04:48:27.288Z",
      "destinations": []
    },
    {
      "id": "xcgvhcfdx",
      "versionId": "dtvbyutbvc",
      "name": "Update Transformations and Publish",
      "description": "",
      "code": "function transformEvent(events) { return events; } ",
      "codeVersion": "1",
      "createdAt": "2021-03-04T10:07:25.513Z",
      "updatedAt": "2021-03-04T10:07:25.513Z",
      "destinations": []
    }
  ]
}

Curl Httpie

curl --location -X GET 'https://api.rudderstack.com/transformations' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
http GET 'https://api.rudderstack.com/transformations' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \

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.

{
  "id": "swderftgy",
  "versionId": "edftgyhu",
  "name": "new Transformations-2",
  "description": "",
  "code": "function transform(events) { return events; } ",
  "codeVersion": "1",
  "createdAt": "2021-03-04T04:48:27.288Z",
  "updatedAt": "2021-03-04T04:48:27.288Z",
  "destinations": []
}

Curl Httpie

curl --location -X GET 'https://api.rudderstack.com/transformations/1pSvMXr651E1gWeErQNQlSQU5Bg' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
http GET 'https://api.rudderstack.com/transformations/1pSvMXr651E1gWeErQNQlSQU5Bg' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \

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 optionalbooleanBy 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 optionalobjectPass a set of JSON events to be tested for your code.code optionalstringUpdate the code of an existing transformation..description optionalstringUpdate the description of a transformation.200: OKThis will update transformation object on basis of id.

{
  "id": "1pHw1RmzAqKpRCNupzHjTGfTrPJ",
  "versionId": "1pIfjTI5cOMnSgutkXjTRldt1n3",
  "name": "new Transformations-2",
  "description": "Hey I am updated",
  "code": "export default function cube(x) { return x * x ; }",
  "codeVersion": "1",
  "createdAt": "2021-03-04T04:48:27.288Z",
  "updatedAt": "2021-03-04T04:48:27.288Z"
}

An example request is as shown:

Curl Httpie

curl --location -X POST 'https://api.rudderstack.com/transformations/1pSvMXr651E1gWeErQNQlSQU5Bg' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
-d  '{
    "name": "name updated"
}'
http POST 'https://api.rudderstack.com/transformations/1pSvMXr651E1gWeErQNQlSQU5Bg' \
name='name updated'
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

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

{
  "success": true
}

Curl Httpie

  curl --location -X DELETE 'https://api.rudderstack.com/transformations/1pSvMXr651E1gWeErQNQlSQU5Bg' \
  -H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
http DELETE 'https://api.rudderstack.com/transformations/1pSvMXr651E1gWeErQNQlSQU5Bg' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \

GET

List all transformation versions

https://api.rudderstack.com/transformations/{id}/versionsGet all your transformation revisions by passing an ID. Request ResponseQuery Parameterscount optionalnumberGets the number of objects in your array. By default it always returns the first 5 objects.orderBy optionalstringYou 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.

{
  "TransformationVersions": [
    {
      "id": "1pIYoILGZTNYZP4YYkeyNIKlitl",
      "versionId": "1pIYoLfEzcMK3D3M1ihjqI02wnx",
      "name": "Update Transformations and Publish",
      "description": "",
      "code": "",
      "codeVersion": "1",
      "createdAt": "2021-03-04T10:07:24.562Z",
      "updatedAt": "2021-03-04T10:07:24.562Z"
    },
    {
      "id": "1pIYoILGZTNYZP4YYkeyNIKlitl",
      "versionId": "1pIhxFXd7NR7XDA914rLAn5f7wq",
      "name": "Update Transformations and Publish",
      "description": "Hey I am updated again",
      "code": "export default function cube(x) { return x * x * x ; }",
      "codeVersion": "1",
      "createdAt": "2021-03-04T11:22:36.102Z",
      "updatedAt": "2021-03-08T04:22:42.646Z"
    }
  ]
}

An example request is as shown:

Curl Httpie

    curl --location -X GET 'https://api.rudderstack.com/transformations/1pIYoILGZTNYZP4YYkeyNIKlitl/versions' \
    -H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
http GET 'https://api.rudderstack.com/transformations/1pIYoILGZTNYZP4YYkeyNIKlitl/versions' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \

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.

{
  "id": "1pIYoILGZTNYZP4YYkeyNIKlitl",
  "versionId": "1pIYoLfEzcMK3D3M1ihjqI02wnx",
  "name": "Update Transformations and Publish",
  "description": "",
  "code": "",
  "codeVersion": "1",
  "createdAt": "2021-03-04T10:07:24.562Z",
  "updatedAt": "2021-03-04T10:07:24.562Z"
}

Curl Httpie

curl --location --request GET 'https://api.rudderstack.com/transformations/1pIYoILGZTNYZP4YYkeyNIKlitl/versions/1pIhxFXd7NR7XDA914rLAn5f7wq' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
http GET 'https://api.rudderstack.com/transformations/1pIYoILGZTNYZP4YYkeyNIKlitl/versions/1pIhxFXd7NR7XDA914rLAn5f7wq' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \

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 optionalbooleanBy default this flag is false. It publishes your library to the latest version if set to true.Body Parametersname requiredstringName of library that you wish to createcode requiredstringCode of library goes here.description optionalstringDescription of the library goes here200: OK

{
  "id": "1pT7qGNwZfGkSqne8OE1EAcRvgK",
  "versionId": "1pT7qEnXP8Dn9tQGiKnKNY0Qwmw",
  "name": "User Defined Library4",
  "description": "Get User context",
  "code": "export default function cube(x) { return x * x * x; }",
  "updatedAt": "2021-03-08T03:53:34.468Z",
  "createdAt": "2021-03-08T03:53:34.468Z",
  "importName": "userDefinedLibrary4"
}

The publish flag for a library works in the same way as for destinations.

Curl Httpie

curl --location -X POST 'https://api.rudderstack.com/libraries' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
-d '{
    "name": "User Defined Library",
    "description": "Get User context",
    "code": "export default function cube(x) { return x * x * x; }"
}'
http POST 'https://api.rudderstack.com/libraries' \
name='User Defined Library' description='Get User context' code='export default function cube(x) { return x * x * x; }' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

GET

List all libraries

https://api.rudderstack.com/librariesGet all the published libraries. Request Response200: OKThis gets a single transformation version.

{
  "libraries": [
    {
      "id": "1pHx15j5rXvmmQUIMBaQdIyrpr2",
      "versionId": "1pHxdlGL8IyoP7WfvRil4Qs88cp",
      "name": "Get Cube",
      "description": "First Library using apiCall",
      "code": "export default function cube(x) { return x * x ; }",
      "createdAt": "2021-03-04T05:01:46.985Z",
      "updatedAt": "2021-03-04T05:01:47.141Z",
      "importName": "getCube"
    },
    {
      "id": "1pT7933tHRBPlEMIZt5Zi3VIht1",
      "versionId": "1pT793mcqQkcyHdqwXkxHmtgMMg",
      "name": "User Defined Library",
      "description": "Get User context",
      "code": "    export default function cube(x) { return x * x * x; }",
      "createdAt": "2021-03-08T03:47:51.512Z",
      "updatedAt": "2021-03-08T03:47:51.512Z",
      "importName": "userDefinedLibrary"
    }
  ]
}

Curl Httpie

curl --location -X GET 'https://api.rudderstack.com/libraries' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
http GET 'https://api.rudderstack.com/libraries' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

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.

{
  "id": "1pT7933tHRBPlEMIZt5Zi3VIht1",
  "versionId": "1pT793mcqQkcyHdqwXkxHmtgMMg",
  "name": "User Defined Library",
  "description": "Get User context",
  "code": "    export default function cube(x) { return x * x * x; }",
  "createdAt": "2021-03-08T03:47:51.512Z",
  "updatedAt": "2021-03-08T03:47:51.512Z",
  "importName": "userDefinedLibrary"
}

Curl Httpie

curl --location -X GET 'https://api.rudderstack.com/libraries/1pT7933tHRBPlEMIZt5Zi3VIht1' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
http GET 'https://api.rudderstack.com/libraries/1pT7933tHRBPlEMIZt5Zi3VIht1' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

Updating a library with publish has same flow as for transformations.

A sample request is as shown:

Curl Httpie

curl --location -X POST 'https://api.rudderstack.com/libraries/1pT7933tHRBPlEMIZt5Zi3VIht1' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
-d '{
    "description": "Get Divisible by 2",
    "code": "export default function cube(x) { return 2 * x; }"
}'
description='Get Divisible by 2' code='export default function cube(x) { return 2 * x; }'
http POST 'https://api.rudderstack.com/libraries/1pT7933tHRBPlEMIZt5Zi3VIht1' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

GET

List all library versions

https://api.rudderstack.com/libraries/{id}/versions

Get all the library revisions for an ID.

Request ResponseQuery Parameterscount optionalnumberBy 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

{
  "libraryVersions": [
    {
      "id": "1pT7933tHRBPlEMIZt5Zi3VIht1",
      "versionId": "1pT793mcqQkcyHdqwXkxHmtgMMg",
      "name": "userDefinedLibrary",
      "description": "Get User context",
      "code": "    export default function cube(x) { return x * x * x; }",
      "createdAt": "2021-03-08T03:47:51.686Z",
      "updatedAt": "2021-03-08T03:47:51.686Z",
      "isPublished": false
    },
    {
      "id": "1pT7933tHRBPlEMIZt5Zi3VIht1",
      "versionId": "1pT8KDAD66mQxnaUQxJpNs9qLFn",
      "name": "userDefinedLibrary",
      "description": "Get Divisible by 2",
      "code": "export default function cube(x) { return 2 * x; }",
      "createdAt": "2021-03-08T03:57:33.738Z",
      "updatedAt": "2021-03-08T03:57:33.738Z",
      "isPublished": true
    }
  ]
}

Curl Httpie

curl --location --request GET 'https://api.rudderstack.com/libraries/1pT7933tHRBPlEMIZt5Zi3VIht1/versions' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
http GET 'https://api.rudderstack.com/libraries/1pT7933tHRBPlEMIZt5Zi3VIht1/versions' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

GET

Retrieve a single library version

https://api.rudderstack.com/libraries/{id}/versions/{versionId}Get a single library revision. Request Response200: OK

{
  "id": "1pT7933tHRBPlEMIZt5Zi3VIht1",
  "versionId": "1pT8KDAD66mQxnaUQxJpNs9qLFn",
  "name": "userDefinedLibrary",
  "description": "Get Divisible by 2",
  "code": "export default function cube(x) { return 2 * x; }",
  "createdAt": "2021-03-08T03:57:33.738Z",
  "updatedAt": "2021-03-08T03:57:33.738Z",
  "isPublished": false
}

Curl Httpie

curl --location -X GET 'https://api.rudderstack.com/libraries/1pT7933tHRBPlEMIZt5Zi3VIht1/versions/1pT8KDAD66mQxnaUQxJpNs9qLFn' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
http GET 'https://api.rudderstack.com/libraries/1pT7933tHRBPlEMIZt5Zi3VIht1/versions/1pT8KDAD66mQxnaUQxJpNs9qLFn' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

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 requiredstringTransformation versionId that needs to be published.testInput optionalstringThis is an array of JSON object in a string format.transformations optionalarrayAn array of object with the property as versionId and testInput.libraries optionalarrayAn array of object with property as versionId.200: OKSends published as true if versions is successfully published.

{
  "published": true
}

The sample request is as shown:

{
  transformations: [
    {
      versionId: publishTransformerVersionId,
      testInput:
        '[
          {
            "anonymousId":"8d872292709c6fbe",
            "channel":"mobile"
          },
          {
            "anonymousId":"8d872292709c6fbe",
            "channel":"mobile"
          }
        ],
  libraries: [
    {
      versionId: publishLibraryVersionId1,
    },
    {
      versionId: publishLibraryVersionId1,
    }
  ]
}

Curl Httpie

curl --location -X POST 'https://api.rudderstack.com/transformations/libraries/publish' \
-H 'Authorization: Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN) \
-H 'Content-Type: application/json' \
-d '{
  transformations: [
    {
      versionId: publishTransformerVersionId,
      testInput:
        '[
          {
            "anonymousId":"8d872292709c6fbe",
            "channel":"mobile"
          },
          {
            "anonymousId":"8d872292709c6fbe",
            "channel":"mobile"
          }
        ],
  libraries: [
    {
      versionId: publishLibraryVersionId1,
    },
    {
      versionId: publishLibraryVersionId1,
    }
  ]
}'
http POST 'https://api.rudderstack.com/transformations/libraries/publish' \
transformations='[{versionId: publishTransformerVersionId, testInput:'[{"anonymousId":"8d872292709c6fbe","channel":"mobile"},{"anonymousId":"8d872292709c6fbe","channel":"mobile"}] libraries='[{versionId: publishLibraryVersionId1,},{versionId: publishLibraryVersionId1}]' \
Authorization: 'Basic Base64Enc(EMAIL_ADDRESS:ACCESS_TOKEN)' \
Content-Type:'application/json'

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

We also support for real-time operations, such as aggregation and sampling.

To know more about the Transformations API, please feel free to . You can also start a conversation in our community, and we will be happy to help you.

Personal Access Tokens
user-specific transformations
contact us
Slack