Salesforce Marketing Cloud Fuel SDK for Python (salesforce-fuelsdk-sans)
The `salesforce-fuelsdk-sans` library is a community-maintained fork of the original Salesforce Marketing Cloud Fuel SDK for Python. It provides easy programmatic access to Salesforce Marketing Cloud's Fuel API Family services, encompassing both REST and SOAP APIs. The SDK streamlines common tasks such as acquiring and refreshing access tokens, managing token state, and determining appropriate API endpoints. The latest stable version, 1.3.1, was released in June 2022.
Warnings
- breaking Version 1.3.1 replaced `suds-jurko` with `suds-community` as a dependency due to `setuptools>=58.0.0` no longer supporting `2to3`. If you are upgrading from an older version of the original FuelSDK-Python or salesforce-fuelsdk-sans and explicitly relied on `suds-jurko`, you might encounter dependency resolution issues.
- gotcha Authentication is a common source of errors. Incorrectly configured Client ID, Client Secret, or tenant-specific endpoints (`authenticationurl`, `baseapiurl`, `soapendpoint`) can lead to 'Unable to validate App Keys' or 'unsupported_grant_type' errors. Ensure these values are correct for your Marketing Cloud instance and application type.
- gotcha The `ET_Client` object should be instantiated once and reused for the entire session. Creating a new `ET_Client` object for each API request can lead to performance overhead and potential issues with token management and endpoint determination.
- gotcha The original `FuelSDK-Python` (before this fork) was reported to have compatibility issues with Python 3.10 and newer versions. While `salesforce-fuelsdk-sans` aims to address this, users migrating from the original SDK should be aware of potential runtime errors if they haven't upgraded to this maintained fork.
Install
-
pip install salesforce-fuelsdk-sans
Imports
- ET_Client
from FuelSDK import ET_Client
Quickstart
import os
from FuelSDK import ET_Client
# Configure environment variables (recommended for production)
# export FUELSDK_CLIENT_ID='YOUR_CLIENT_ID'
# export FUELSDK_CLIENT_SECRET='YOUR_CLIENT_SECRET'
# export FUELSDK_AUTH_URL='YOUR_AUTH_TENANT_SPECIFIC_ENDPOINT'
# export FUELSDK_BASE_API_URL='YOUR_REST_TENANT_SPECIFIC_ENDPOINT'
# export FUELSDK_SOAP_ENDPOINT='YOUR_SOAP_TENANT_SPECIFIC_ENDPOINT'
try:
# Initialize ET_Client. Pass False for debug, False for account_id (unless using multi-org)
# Configuration can be passed as a dictionary, read from ~/.fuelsdk/config.python,
# or via environment variables (as shown below).
myClient = ET_Client(False, False)
# Example: Retrieve a list of lists
etList = myClient.create_object('List')
etList.props = {'Name': 'My New List', 'Description': 'Created via FuelSDK-Sans'}
results = etList.post()
if results.status:
print(f"Successfully created list: {results.results[0]['NewID']}")
else:
print(f"Error creating list: {results.results[0]['ErrorMessage']}")
print(f"Full response: {results.results}")
# Example: Get all lists
# etList = myClient.create_object('List')
# results = etList.get()
# if results.status:
# print(f"Found {len(results.results)} lists.")
# for lst in results.results:
# print(f" List Name: {lst['ListName']}, ID: {lst['ID']}")
# else:
# print(f"Error retrieving lists: {results.results[0]['ErrorMessage']}")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure environment variables or config file are correctly set.")