Journey builder's custom activity: Fetch data extension data in bulk

2k Views Asked by At

I am new to Salesforce Marketing Cloud and journey builder. https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/creating-activities.html We are building journey builder's custom activity in which it will use a data extension as the source and when the journey builder is invoked, it will fetch a row and send this data to our company's internal endpoint. The team got that part working. We are using the postmonger.js.

I have a couple of questions:

  1. Is there a way to retrieve the data from data extension in bulk so that we can call our company's internal bulk endpoint? Calling the endpoint for each record in the data extension for our use case would not be efficient enough and won't work.

  2. When the journey is invoked and an entry in the data extension is retrieved and that data is sent to our internal endpoint, is there a machanism to mark this entry as already sent such that next time the journey is run, it won't process the entry that's already sent?

Here is a snippet of our customActivity.js in which this is populating one record. (I changed some variable names.). Is there a way to populate multiple records such that when "execute" is called, it is passing a list of payloads as input to our internal endpoint.

function save() {
        try {
            var TemplateNameValue = $('#TemplateName').val();
            var TemplateIDValue = $('#TemplateID').val();
            let auth = "{{Contact.Attribute.Authorization.Value}}"
            payload['arguments'].execute.inArguments = [{
                "vendorTemplateId": TemplateIDValue,
                "field1": "{{Contact.Attribute.DD.field1}}",
                "eventType": TemplateNameValue,
                "field2": "{{Contact.Attribute.DD.field2}}",
                "field3": "{{Contact.Attribute.DD.field3}}",
                "field4": "{{Contact.Attribute.DD.field4}}",
                "field5": "{{Contact.Attribute.DD.field5}}",
                "field6": "{{Contact.Attribute.DD.field6}}",
                "field7": "{{Contact.Attribute.DD.field7}}",
                "messageMetadata" : {}
            }];

            payload['arguments'].execute.headers = `{"Authorization":"${auth}"}`;
            payload['configurationArguments'].stop.headers = `{"Authorization":"default"}`;
            payload['configurationArguments'].validate.headers = `{"Authorization":"default"}`;
            payload['configurationArguments'].publish.headers = `{"Authorization":"default"}`;
            payload['configurationArguments'].save.headers = `{"Authorization":"default"}`;
            payload['metaData'].isConfigured = true;
            console.log(payload);
            connection.trigger('updateActivity', payload);
        } catch(err) {
            document.getElementById("error").style.display = "block";
            document.getElementById("error").innerHtml = err;
        }
        console.log("Template Name: " + JSON.stringify(TemplateNameValue));
        console.log("Template ID: " + JSON.stringify(TemplateIDValue));
    }
});

Any advise or idea is highly appreciated! Thank you. Grace

1

There are 1 best solutions below

0
On

Firstly, i implore you to not proceed with the design pattern of fetching data for each subscriber, from Marketing Cloud, that gets sent through the custom activity, for arguments sake i'll list two big issues.

You have no way of limiting the configuration of data extensions columns or column names in SFMC (Salesforce Marketing Cloud). If any malicious user or by human error would delete a column or change a column name your service would stop receiving that value.

Secondly, Marketing Cloud has 2 sets of API limitations, yearly and minute by minute. Depending on your licensing, you could run into the yearly limit.

The problem you have with limitation on minutes (2500 for REST and 2000 for SOAP) is that each usage of the custom activity in journey builder would multiple the amount of invocations per minute. Hitting this limit would cause issues for incremental data flows into SFMC.

I'd also suggest not retrieving any data from Marketing Cloud when a customer gets sent through a custom activity. Users should pick which corresponding rows/data that should be sent to the custom activity in their segmentation.

The eventDefinitionKey can be picked up from postmonger after requestedTriggerEventDefinition in the eventDefinitionModel function. eventDefinitionKey can then be used to programmatically populate SFMC's POST call with data from the Journey Data model, thus allowing marketers to select what data to be sent with the subscriber.

Following is some code to show how it would work in your customActivity.js

connection.on(
  'requestedTriggerEventDefinition',
  function (eventDefinitionModel) {
    var eventKey = eventDefinitionModel['eventDefinitionKey'];
    save(eventKey);
  }
);

function save(eventKey) {
  // subscriberKey fetched directly from Contact model
  // columnName is populated from the Journey Data model
  var params = {
    subscriberKey: '{{Contact.key}}',
    columnName: '{{Event.' + eventKey + '.columnName}}',
  };
  payload['arguments'].execute.inArguments = [params];
}