Push to APIs
Learn how to use the transformation scripts to push data directly to your API
Overview
This guide walks through how to leverage the transformation script to send data from a source directly to your API during a hotglue job. This should be used instead of a target. We will be using the Python requests library to do this.
Reasoning
We recommend using the Python transformation script to connect with your API for more flexibility. You can:
- handle authorization (for example, you can read/write api keys for your tenants using the tenant config)
- do any mapping necessary to your internal schema
- manage the order requests are made in
- and more!
Setup your environment
Dependencies
The script we will walk through is tested with the following requirements.txt
– if you have a different desired behavior, verify your dependency versions match.
Sample data
For this example we will be working with Mailchimp list members test data. Download the CSV here to follow along.
Sample Script
Prepare the data
Refer to the sample script below which:
- Reads the
list_members
CSV as pandas dataframe, and - Does some light transformation on the data
Send to the API
Now that the data has been mapped to our schema, we can create a payload and POST it to our API. If you’d like to learn more about the requests library syntax, visit their docs.
Refer to the sample script below: