Journey Builder API

 

JOURNEY BUILDER API

JOURNEY BUILDER API ALLOWS YOU TO PROGRAMMATICALLY ACCESS AND INTERACT WITH JOURNEY BUILDER FUNCTIONALIITES.


STEP BY STEP GUIDE TO TRIGGER JOURNEY BUILDER API :

STEP 1 : CREATE AN INSTALL PACKAGE 

Create an installed package in your marketing cloud account to create API integration, click here to read more.

 

Give package name and description




 Choose API integration as Component



Select Server-to-Server as your integration type




Choose your scope for the integration and save.



STEP 2 : TEST YOUR INTEGRATION 
 
Install postman and test your integration, to install postman click here



Request SFMC token :

API - https://{{et_subdomain}}.auth.marketingcloudapis.com/v2/token

Body -

{
    "grant_type""client_credentials",
    "client_id""{{et_clientId}}",
    "client_secret""{{et_clientSecret}}",
    "account_id""{{et_mid}}"
}


From the installed package summary, update your Authentication base URI and update your body with Client Id, Secret and MID (optional).

STEP 3  : CREATE A JAVASCRIPT CODE RESOURCE 

In Marketing Cloud, you can also create a code resource or content block and add the below code snippet for generating access token

<script runat="server" language="javascript">
  Platform.Load("core", "1");
  var MemberID = Platform.Recipient.GetAttributeValue('memberid');
  var ClientId = get_config[0]["Client_ID"];
  var ClientSecret= get_config[0]["Client_Secret"];
  var url = 'domain/v2/token';
  var ContentType = 'application/json';
  var payload = {
    "client_id": ClientId,  
    "client_secret": ClientSecret,
    "grant_type": "client_credentials"
  };
  try{
    var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
    var statusCode = accessTokenResult["StatusCode"];
    var response = accessTokenResult["Response"][0];
    var accessToken = Platform.Function.ParseJSON(response).access_token;
    Variable.SetValue("@accessToken",accessToken);
  }
  catch(e)
  {
     Write(e.message);
  }
</script>

STEP 4  : CREATE A MULTI-STEP JOURNEY WITH API EVENT SOURCE



Drag and Drop API Event entry source into your canvas 


Click on the API Event activity and create a new API Event , while creating a new event API you should also build a sendable data extensions for the Journey, select the sendable data extension and save it.


Configure your journey, validate and activate it. Once Activated copy the event definition key, you may store client Id, secret, AUTH, REST and SOAP API into a data extension.


STEP 5  : Validate you configuration via POSTMAN 

Fire Entry Event : 
URI - https://{{et_subdomain}}.rest.marketingcloudapis.com/interaction/v1/events

Body -
{
    "ContactKey""DD301",
    "EventDefinitionKey""APIEvent-0dbe46de-74f9-a309-7778-298c0a565f93",
    "Data": {
        "SubscriberKey""DD301",
        "Email""b2.shashi@gmail.com",
        "First_Name""Shashi",
        "Last_Name""Prasad"
    }
}

STEP 6   : Design a content block for Journey Entry Interaction

Add the below code snippet and update the details as required 
%%[
      SET @EstablishContactKey= 'True'
      SET @url = Concat('DOMAIN/interaction/v1/events')
      SET @content = concat('
       {  
      "ContactKey": "',@SubscriberKey,'",
      "EventDefinitionKey": "',@Journey_API_Key,'",
      "EstablishContactKey": "',@EstablishContactKey,'",
      "Data": {
       "SubscriberKey" : "',@SubscriberKey,'",
       "EMAIL": "',@EMAIL,'",
       "FIRST_NAME" : "',@FIRST_NAME,'",
       "LAST_NAME" : "',@LAST_NAME,'"
      }
     }                                  
     ')
     SET @returnValid =HTTPPOST2(@url,"application/json; charset=UTF-8",@content,
      false, @output, @respheader, 'Authorization', CONCAT('Bearer  
     ',@accessToken))    
]%%

STEP 7  : Built and design your cloud page to trigger interaction via Journey API event

Call code snippet built in step 3 and step 6 into your cloud page leveraging ConentBlockByKey AMPscript functions.
Or, you may combine the code into a single block as :
<script runat="server" language="javascript">
  Platform.Load("core", "1");
  var MemberID = Platform.Recipient.GetAttributeValue('memberid');
  var ClientId = get_config[0]["Client_ID"];
  var ClientSecret= get_config[0]["Client_Secret"];
  var url = 'domain/v2/token';
  var ContentType = 'application/json';
  var payload = {
    "client_id": ClientId,  
    "client_secret": ClientSecret,
    "grant_type": "client_credentials"
  };
  try{
    var accessTokenResult = HTTP.Post(url, ContentType, Stringify(payload));
    var statusCode = accessTokenResult["StatusCode"];
    var response = accessTokenResult["Response"][0];
    var accessToken = Platform.Function.ParseJSON(response).access_token;
    Variable.SetValue("@accessToken",accessToken);
  }
  catch(e)
  {
     Write(e.message);
  }
</script>

%%[
      SET @EstablishContactKey= 'True'
      SET @url = Concat('DOMAIN/interaction/v1/events')
      SET @content = concat('
       {  
      "ContactKey": "',@SubscriberKey,'",
      "EventDefinitionKey": "',@Journey_API_Key,'",
      "EstablishContactKey": "',@EstablishContactKey,'",
      "Data": {
       "SubscriberKey" : "',@SubscriberKey,'",
       "EMAIL": "',@EMAIL,'",
       "FIRST_NAME" : "',@FIRST_NAME,'",
       "LAST_NAME" : "',@LAST_NAME,'"
      }
     }                                  
     ')
     SET @returnValid =HTTPPOST2(@url,"application/json; charset=UTF-8",@content,
      false, @output, @respheader, 'Authorization', CONCAT('Bearer  
     ',@accessToken))    
]%%






Comments


Knowledge Article

Most Viewed

CLOUD PAGE ENABLEMENT - PART 1

EMAIL NOT SENT IN JOURNEY BUILDER

CONSIDERATIONS FOR JOURNEY BUILDER

Journey Builder REST API Documentation

Preference Center Demystified

Popular Posts

CLOUD PAGE ENABLEMENT - PART 1

EMAIL NOT SENT IN JOURNEY BUILDER

CONSIDERATIONS FOR JOURNEY BUILDER

Journey Builder REST API Documentation

Preference Center Demystified

SEND LOG EANBLEMENT

Share with Friends

Disclaimer:

The information provided on this technical blog is for general informational purposes only. As a SFMC (Salesforce Marketing Cloud) Technical Architect, I strive to offer accurate and up-to-date content related to SFMC and its associated technologies. However, please note that technology is constantly evolving, and the information provided may become outdated or inaccurate over time.

The content published on this blog represents my personal views and experiences as a SFMC Technical Architect and does not necessarily reflect the official views or opinions of any organization or employer I may be affiliated with.

While I make every effort to ensure the accuracy and reliability of the information presented, I cannot guarantee its completeness, suitability, or applicability to your specific circumstances. Therefore, it is essential to verify any information provided and make your own independent assessments or seek professional advice if needed.

Furthermore, any actions taken based on the information provided on this blog are at your own risk. I shall not be held liable for any damages, losses, or inconveniences arising from the use of the information presented here.

Please keep in mind that SFMC and its associated technologies are complex and require technical expertise for proper implementation and management. It is recommended to consult with qualified professionals or official SFMC documentation for comprehensive guidance.

Finally, please note that any product or company names mentioned on this blog are trademarks or registered trademarks of their respective owners. The mention of these trademarks or registered trademarks does not imply any endorsement or affiliation with the blog.

By accessing and using this blog, you agree to the terms of this disclaimer. If you do not agree with any part of this disclaimer, please refrain from using this blog.