3

We're building a Custom Activity that will send a push message to a external platform from Journey Builder. In usage of the Journey, a Emailactivity will update the Entry Event data extension, adding a vouchercode.

We need to retrieve this updated(!) vouchercode in our custom activity, retrieving the voucher that was claimed in the previous mail form the updated Entry Event data extension

Databinding {{Event.my-entry-event.Vouchercode}} seems not an option here, as it will only use the Entry event fields as they were at the time of entrying the Journey. Also, adding the dataextensions of the entry event(s) to the Data Model will become messy {{Contact.Attributes.My-DE.Vouchercode}}, so the client preferred not to depend on that.

We now try to retrieve the updated data by the SFMC REST API on the /execute endoint, but that will cause a lot of external API requests, esspecially if they need to retrieve Bearer tokens first. e.g. for each customer /execute:

       //Retrieve token
 thenrequest('POST',
        `https://${process.env.SFMC_SUBDOMAIN}.auth.marketingcloudapis.com/v2/token/`, {
            json: sfmc_auth_req
        })
    .getBody('utf8')
    .then(JSON.parse).done(function (res) {
        token = res.access_token;

         //Retrieve updated data from entry event data extension
        thenrequest('GET', `https://${process.env.SFMC_SUBDOMAIN}.rest.marketingcloudapis.com/data/v1/customobjectdata/key/${dename}/rowset?$filter=guid%20eq%20'${requestObject.guid}'`, {
                headers: {
                    'Authorization': 'Bearer ' + token
                }
            })
            .getBody('utf8').then(JSON.parse).done(function (res) {
               
                //Replace attributes with updated attributes as received from API
                for (var key in res.items[0].values) requestObject[key] = res.items[0].values[key];

                //post requestobject to external PUSH MESSAGE API
            });
    });

Question: Isn't there a way that you can make direct lookups in a Dataextension from a Custom Activity without the use of the REST api, or otherwise at least skip the Token retrieval process for each user as I assume the system must have a token available when running through the activity?

It seems like such a simple problem, retrieving the updated(!) data from the entry event, so probably i'm overlooking something.

According to the link below it seems that Databinding fields are updated on Publish and every hour. Is this really true? (I'm running an experiment now. UPDATE: that's not the case, Atrributes remain 'as they were' on entering the Journey and will not get updated after entering the Journey.)

https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/how-data-binding-works.html#supported-methods-of-data-binding

Event Context You can reference an event within an expression (the incoming data associated with the entry event). Adhere to the {{Event.my-custom-product-entry-event-key.ProductId}} Evaluating Expressions An activity can ..etc... When processing a contact in a journey, the engine evaluates all expressions. Once a journey publishes, and every subsequent hour, the system compiles each expression to ensure evaluation at runtime.

Hope someone can give me some advice on how to deal with this issue.

0

To avoid a lot of "Get-Token-Requests" you can implement a class at your app, which will handle the auth against the SFMC (and also the part of refeshing the token). The received token will be stored in something like a cache instance. Now, when an endpoint is called, this endpoint will not do auth against the SFMC API, instead it will get the token from your class, which will decide whether a valid token is available or a new auth / refresh call must be done.

Make sure, your class instance can handle parallel executions and avoid race conditions by following the mutex design pattern.

This construct will avoid you from a lot of unnecessary auth requests and also from resulting race conditions, when tokens are not longer available cause a new one was requested by another instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.