Salesforce Marketing Cloud Fuel SDK for Python (salesforce-fuelsdk-sans)

1.3.1 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `ET_Client` and perform a basic API call, such as creating a new list. It relies on environment variables for authentication credentials, which is a recommended practice. The `ET_Client` manages access token acquisition and refresh automatically.

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.")

view raw JSON →