Salesforce Marketing Cloud (SFMC) has two different API types in use: a Rest API and a SOAP API. Within the Python ecosystem, a library called FuelSDK integrates with the Salesforce Marketing Cloud APIs. With it, it is possible to integrate directly with SFMC. It is also possible to use automation within Salesforce Marketing Cloud to pick up data from an FTP here; however, I will focus on data integration using SFMC’s REST API.
Pushing data to Salesforce Marketing Cloud usually happen in two flavors:
A data extension in SFMC is a data repository backed by a MS SQL backend. It is normally used in SFMC to provide the right type of journeys for automated journeys.
The trigger send endpoint is responsible for updating your contact information with the new information, providing the data to a data extension, and trigger an email. It is usually used for transactional style of emails that need to be processed right away.
Authorization with the salesforce marketing cloud rest API can be done through an Oauth2 request token call:
The response is in the following JSON format and contains an access token. This token is valid for a limited period of time, but a new access token can be requested again using either the clientId and Secret or the refresh token.
Using the rest API data events endpoint, it is possible to upload multiple mini-batch events to the salesforce marketing cloud. There is a limitation of 5MB to push and a recommendation to only send up to 50 rows at a time.
Trigger sends work in a similar way to data extension endpoints but has different payloads that need to be provided. It contains a field Subscriber attributes that can be used to provide the data necessary to a data extension or contact update.
an example call can then be:
With 202 accepted response in the following format:
Once the trigger send has been processed, it will update the required contact and data extension depending on the configuration set up in Salesforce Marketing Cloud.
When generating async trigger sends call when often want to get some insight on the status. The SFMC Rest API support these kinds of calls:
With the following type of response being provided on sent success:
Providing data to SFMC using its Rest API is straightforward. Setting up the different calls in python allows to set up recurring jobs easily using tools such as Airflow.