Salesforce Marketing Cloud Developer Edition Recipes

repository·master·Indexed 41 days ago

https://github.com/sfmcdg/salesforce-marketing-cloud-developer-edition-recipes

A collection of instructional recipes and developer notes for common tasks and integrations within the Salesforce Marketing Cloud Developer Edition environment. Includes guides on Fuel API authentication (OAuth 2.0), managing access and refresh tokens, configuring Journey Builder interactions, and firing events via Automation Studio.

Tokens
10.8K
Snippets
18
Records
44
Agent score
52%

What's inside Salesforce Marketing Cloud Developer Edition Recipes

  1. Explore Salesforce Marketing Cloud Developer Edition Recipes

    master

    This repository provides a collection of 'recipes' designed to help developers get started with Salesforce Marketing Cloud development. Each recipe provides instructions (methods) and required components (ingredients) to implement specific functional tasks.

    Available recipes include:

    • Authentication with Marketing Cloud: How to authenticate with the platform.
    • Sending an email with Journey Builder: A step-by-step guide for email delivery via Journey Builder.
    • Firing Events in Journey Builder Interactions: How to trigger events within interactions.
    • Starting an Automation: Instructions for initiating automations.
  2. How Events, Triggers, and Interactions work together

    master

    In Salesforce Marketing Cloud, an Interaction is the lifecycle of a customer journey that starts when an Event is fired.

    1. Event: An action that triggers the process (e.g., a REST API call or an Automation in Automation Studio).
    2. Trigger: The mechanism that 'hears' the Event. It contains Contact Filter Criteria that determine which specific contacts enter the Interaction.
    3. Interaction: The automated journey itself. Once a contact meets the Trigger criteria, they enter the Interaction to undergo defined activities (like updating data or sending emails).
  3. Understand the refresh token lifecycle

    master

    The refresh token mechanism follows these rules:

    1. Initial Request: Include "accessType": "offline" to receive a refreshToken in the initial response.
    2. Token Rotation: Every time you use a refreshToken to get a new accessToken, the server issues a new refreshToken.
    3. Invalidation: Once a refreshToken has been used to request a new token, it is invalidated. You must store and use the most recent refreshToken provided in the response to avoid authentication failures.
  4. Manage OAuth access tokens efficiently

    master

    Do not request a new token for every API call. Tokens are typically valid for 3,600 seconds (1 hour). Frequent authentication requests can lead to rate limiting or throttling.

    Use one of the following strategies to manage tokens:

    1. Use Fuel SDKs: Use official SDKs from the ExactTarget GitHub which handle token acquisition and refreshing automatically.
    2. Try-Catch Pattern: Attempt your API request. If you receive a 401 Unauthorized response, catch the error, request a new token, and retry the request.
    3. Track Expiry: Store the expiresIn value as a timestamp. Check the token's validity in memory or via a scheduled cron job before making an API request to ensure it hasn't expired.
  5. Understand Marketing Cloud App types and use cases

    master

    Marketing Cloud uses the Fuel Authentication Service (based on OAuth 2.0) to manage API access. Before using Fuel API methods, you must create an app in the Marketing Cloud App Center to obtain a clientId and clientSecret.

    There are four primary app templates:

    1. API Integration: Used for authenticating and managing permissions for REST or SOAP API methods.
    2. Marketing Cloud: Custom apps hosted externally and presented via iframe within the platform. They use JSON Web Tokens (JWT) for Single Sign-On (SSO) and can be published to the HubExchange marketplace.
    3. Application Extension: Similar to Marketing Cloud apps (providing SSO), but intended for custom Journey Builder Triggers, Activities, Cloud Editor Blocks, or Automation Studio activities without requiring formal certification.
    4. MobilePush: Provides authentication for iOS, Android, and Amazon mobile applications using the Journey Builder for Apps SDK.
  6. How to use AMPScript delimiters

    master

    AMPScript is a server-side scripting language used to embed logic and data into HTML emails, landing pages, and SMS messages. There are two primary ways to wrap AMPScript code depending on whether you are writing a script block or an inline function call:

    1. Script Function Blocks: Use these for multi-line logic or script blocks. Wrap the code with %%[ and ]%% delimiters.
    2. Inline AMPScript: Use these for single function calls or when you need to output a value directly into the document. Wrap the code with %%= and =%% delimiters.

    Note: AMPScript is processed on the server before the document reaches the client; the recipient only sees the rendered output.

    /* Script Block */
    %%[ 
      /* Your logic here */ 
    ]%%
    
    /* Inline AMPScript */
    %%=function()=%%
  7. Install the Marketing Cloud Connector V5

    master

    To install the connector package into Salesforce:

    1. Log in to Salesforce as an administrator.
    2. Use the installation link provided in the official documentation (e.g., https://login.salesforce.com/packaging/installPackage.apexp?p0=...). Note: Always use the most recent link from the official documentation.
    3. Install using default settings as an administrator.
    4. Wait for a confirmation email from Salesforce.
    5. To verify installation, check the following URL in Salesforce: https://ap1.salesforce.com/0A3?setupid=ImportedPackage.
  8. Create an Attribute Group to link Contact Records and Data Extensions

    master

    An Attribute Group defines the relationship between a Contact Record and your Data Extension in the Data Designer.

    Setup Steps:

    1. In Contact Builder, select the Data Designer menu.
    2. Click Create Attribute Group, provide a name, and click Create.
    3. Click Link Data Extensions and select your previously created Data Extension.
    4. Define the Relationship:
      • Link Contact Key to your Data Extension's unique identifier (e.g., Email Address).
      • Set the relationship to Root by selecting One from the menu next to the Data Extension name.
      • Select the Use as root option.
      • Click Save.
  9. Execute SOAP requests via cURL

    master

    You can test SOAP envelopes by saving them as a file (e.g., request.xml) and using cURL.

    Command Template:

    curl -XPOST -H "Content-type: text/xml; charset=utf-8" -H "SOAPAction: <ACTION_VERB>" -d @request.xml <ENDPOINT_URL>

    Required Adjustments:

    1. Update the SOAPAction header to reflect the action being used (e.g., Retrieve or Perform).
    2. Update the endpoint URL to match your specific account's endpoint.
    curl -XPOST -H "Content-type: text/xml; charset=utf-8" -H "SOAPAction: Retrieve" -d @request.xml https://webservice.s7.exacttarget.com/Service.asmx