Thursday, 6 May 2021

Integration of Salesforce Marketing Cloud with Open Source CRM System using Rest API

INTRODUCTION

While working on one of the requirements for a transportation sector project for a client based out of Melbourne, Australia there was a requirement to import existing records\leads into the Salesforce Marketing Cloud from third party open source CRM system.

We also needed to provide specifications to add lead into SFMC on the fly from an external CRM system by doing necessary configuration. Given specifications are to be used by other CRM team to insert record from CRM to SFMC on the fly. Below are the detailed steps we need to follow:

APPROACH

1) For importing existing data into Salesforce Marketing Cloud, we have created Data Extension and fields into SFMC and used CSV Import.

2) For integration with third party system, Marketing Cloud provides two APIs that uses OAuth 2 authentication mechanism:
  • The REST API gives you more access to Marketing Cloud features.
  • The SOAP API gives you complete access to most email features.

In this scenario, we have used REST API to integrate with external system. 

Marketing Cloud administrator user is required to perform the actions needed for configuration. Following steps are executed in SFMC.

  • Log in as Marketing Cloud Administrator user in SFMC.
  • Go to Setup -> Apps ->Installed Packages.
  • Click New to create a new package.
  • In the New Package Details window, enter the Name and Description of the package.
  • Click on the Save button.
  • Click on Add Component and will open one pop-up window for setup.
  • In pop-up, select API Integration and click Next. 

  • Select Server-to-Serveras Integration type then click Next.
  • Select required permission for API and click the Save button. Permission can be updated in future, if required.
  • Copy Client Id, Client secret, Authentication URL, and REST URL which will be used for API integration in future steps.

  • Getting Access Token
    • Example Request:
      • Authentication endpoint can be retrieved from the above step.
      • Endpointhttps://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/token
      • Method: POST
      • Content-Type: application/json
    • Request Body:
  • {
    "grant_type": "client_credentials",
    "client_id": "7a9j47upktedde30uedl822p",
    "client_secret": "195527892567524157"
    • Example Response : HTTP/1.1 200 OK
    • Response Body:
  • {
    "access_token":"eyJhbLciOiJIPzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjIifQ.eyJhY2Nlc3NfdG9rZW4iOiJhYmJUQTlpSHZqRjkyd3Jkb0xWZEFCaloiLCJjbGllbnRfaWQiOiI3ZTRmYW1xaWUzcWtzdzlhNDRrcmxvZDgiLCJlaWQiOjEwNzU3Njc2LCJzdGFja19rZXkiOiJRQTFTMSJ9.wSFfEdeNrkoiU_tnmJ2ihm8iUqnJKlZoI3GlavTGBhs.hU4EsiC1e9txh_TCt90YlI2l7xZZ5E6_oa0xku3Jj9CCk1B72M4bhO3kUIyhwfVuB0MFbL0y9KD_RRFzg-nuqPgjPyONnby-iWopdZPBHd-3woupxCMST5-vfJO9qAED9qiUfYLS4WmHRuJTCX4NPScyu8BdROTVEe-D3iAoAeFoJX_rLZ9d5eEhIn1AvkYgoj9siuxAprHEvmySTgNIXkQA6uT_IQ-H1dbfOyJmlFKpYzvhvHb0KH7NJ24zy5bd2MQ5",
    "expires_in":1080,
    "token_type":"Bearer",
    "rest_instance_url":"mc563885gzs27c5t9-3k636tzgm.rest.marketingcloudapis.com",
    "soap_instance_url":"mc563885gzs27c5t9-63k636tzgm.soap.marketingcloudapis.com",
    "scope": "email_read email_write email_send"
    
    }

  • Upsert records in Data Extension: 
    • In a single synchronous call, the API upserts multiple data extension rows. The maximum size of a payload is 5 megabytes. We can post a maximum of 50 fields and 50 records at a time as a best practice.
    • Example Request: 
      • Host:https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com/hub/v1/dataeventsasync/key:YOUR_KEY/rowset
      • Method: POST
      • Content-Type: application/json
      • Authorization: Bearer YOUR_ACCESS_TOKEN
    • Request Body 

  • [ { "keys":{ "Email": "someone@example.com"}, "values":{ "LastLogin": "2013-05-23T14:32:00Z", "IsActive": true, "FirstName": "John", "FollowerCount": 2, "LastName": "Smith" } }, { "keys": {"Email": "someone2@example.com"}, "values":{ "LastLogin": "2013-05-23T14:32:00Z", "IsActive": true, "FirstName": "Jane", "FollowerCount": 2, "LastName": "Smith" } } ]
    • Example Response : HTTP/1.1 200 OK
    • Response Body:
  • [
         {
             "keys": {
                     "Email": "someone@example.com"
                     },
             "values": {
                     "LastLogin": "2013-05-23T14:32:00Z",
                     "IsActive": true,
                     "FirstName": "John",
                     "FollowerCount": 2,
                     "LastName": "Smith"
                     }
         },
         {
             "keys": {
                     "Email": "someone2@example.com"
                     },
             "values": {
                     "LastLogin": "2013-05-23T14:32:00Z",
                     "IsActive": true,
                     "FirstName": "Jane",
                     "FollowerCount": 2,
                     "LastName": "Smith"
                     }
         }
     
  • API returns a 400 response for an an invalid request with details on the error.

SUMMARY
Using Salesforce Marketing cloud APIs, third party open source CRM can be integrated with SFMC. APIs and its sample responses are used to add records on the fly into SFMC. For further details you can refer to this Link!

If you have any questions you can reach out our Salesforce Consulting team here.

No comments:

Post a Comment