Updating Transformation Code using Hevo API

You can apply Transformations on ingested Events to convert or transform them as per your requirement before loading to the Destination. For example, you may want to convert all booleans to 0s and 1s or trim special characters or spaces from values. Operations like these can be done using Transformations.

You can use Hevo API to apply Transformations on your data and also modify existing Transformations. Read Update Transformation code to try out your API requests and get sample responses.

To make the API request, you need to provide the Basic token to make the API request. The Basic token is the combination of your API Secret and Key from your API credentials. Read Generating your API credentials.

Here is an example of updating the Transformation code using Hevo API in different language formats. Replace the sample values with your own to use this script.

Using cURL:

curl --location --request PUT 'https://us.hevodata.com/api/public/v2.0/pipelines/329/transformations' \  # replace "329" with the ID of your Pipeline
--header 'Authorization: Basic <auth_token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "script": "from io.hevo.api import Event\n\n\ndef transform(event):\n    eventName = event.getEventName()\n    properties = event.getProperties()\n    properties['\''foo'\''] = '\''bar'\''\n\n    return event\n"
}' # replace with the python script of the transformation you want to apply

Using Python:

import requests
import json

url = "https://us.hevodata.com/api/public/v2.0/pipelines/329/transformations" # replace "329" with the ID of your Pipeline

payload = {
  "script": "from io.hevo.api import Event\n\n\ndef transform(event):\n    eventName = event.getEventName()\n    properties = event.getProperties()\n    properties['foo'] = 'bar'\n\n    return event\n"
} # replace with the python script of the transformation you want to apply
headers = {
  'Authorization': 'Basic <auth_token>',
  'Content-Type': 'application/json'
}

response = requests.request("PUT", url, headers=headers, json=payload)
print(response.text)