0

guys!

Just to provide a brief overview of what we're working on, we have a business case where he needs to use a custom activity in Journey Builder. We are using a data extension as an input and a data source to execute the journey, and we want some data extension fields to be retrieved by the custom activity so that we can use that data in a call to a sending service.

We are following the documentation at https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-app-development.meta/mc-app-development/example-rest-activity.htm | https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/how-data-binding-works.htm and so far we have not been successful.

These fields I want to retrieve from the data extension, 'EmailAddress', 'Phone' and 'Message'.

'Config.json' to bind the data:

    {
  "workflowApiVersion": "1.1",
  "metaData": {
    "icon": "images/icon.png",
    "category": "message"
  },
  "type": "REST",
  "lang": {
    "en-US": {
      "name": "Send WhatsApp",
      "description": "Send a whatsApp message.",
      "step1Label": "Configure WhatsApp"
    }
  },
  "arguments": {
    "execute": {
      "inArguments": [
        {
          "phone": "{{Contact.Attribute.NameDataExtension.phone}}"
        },
        {
        "email": "{{InteractionDefaults.Email}}"
        }
      ],
      "outArguments": [],
      "url": "https://urltest.herokuapp.com/journeybuilder/execute",
      "verb": "POST",
      "useJwt": true,
      "timeout": 10000
    }
  },
  "configurationArguments": {
    "applicationExtensionKey": "c1009dfa-eb0b-48c5-8521-3c8da1e34bb9",
    "save": {
      "url": "https://urltest.herokuapp.com/journeybuilder/save",
      "verb": "POST",
      "useJwt": true
    },
    "publish": {
      "url": "https://urltest.herokuapp.com/journeybuilder/publish",
      "verb": "POST",
      "useJwt": true
    },
    "stop": {
      "url": "https://urltest.herokuapp.com/journeybuilder/stop",
      "verb": "POST",
      "useJwt": true
    },
    "validate": {
      "url": "https://urltest.herokuapp.com/journeybuilder/validate",
      "verb": "POST",
      "useJwt": true
    }
  },
  "wizardSteps": [
    { "label": "Configure Activity", "key": "step1" }
  ],
  "userInterfaces": {
    "configModal": {
      "height": 400,
      "width": 1000,
      "fullscreen": false
    }
  },
  "schema": {
    "arguments": {
      "execute": {
        "inArguments": [],
        "outArguments": []
      }
    }
  }
}

'Activity.js' Where would I look for the data retrieved from the platform and use it for another call.

'use strict';
var util = require('util');

// Deps
const Path = require('path');
const JWT = require(Path.join(__dirname, '..', 'lib', 'jwtDecoder.js'));
var util = require('util');
var http = require('https');
var axios = require('axios');

exports.logExecuteData = [];

function logData(req) {
    exports.logExecuteData.push({
        body: req.body,
        headers: req.headers,
        trailers: req.trailers,
        method: req.method,
        url: req.url,
        params: req.params,
        query: req.query,
        route: req.route,
        cookies: req.cookies,
        ip: req.ip,
        path: req.path,
        host: req.host,
        fresh: req.fresh,
        stale: req.stale,
        protocol: req.protocol,
        secure: req.secure,
        originalUrl: req.originalUrl
    });
    console.log("body: " + util.inspect(req.body));
    console.log("headers: " + req.headers);
    console.log("trailers: " + req.trailers);
    console.log("method: " + req.method);
    console.log("url: " + req.url);
    console.log("params: " + util.inspect(req.params));
    console.log("query: " + util.inspect(req.query));
    console.log("route: " + req.route);
    console.log("cookies: " + req.cookies);
    console.log("ip: " + req.ip);
    console.log("path: " + req.path);
    console.log("host: " + req.host);
    console.log("fresh: " + req.fresh);
    console.log("stale: " + req.stale);
    console.log("protocol: " + req.protocol);
    console.log("secure: " + req.secure);
    console.log("originalUrl: " + req.originalUrl);
}

/*
 * POST Handler for / route of Activity (this is the edit route).
 */
exports.edit = function (req, res) {
    // Data from the req and put it in an array accessible to the main app.
    //console.log( req.body );
    logData(req);
    res.send(200, 'Edit');
};

/*
 * POST Handler for /save/ route of Activity.
 */
exports.save = function (req, res) {
       // alert("Save");
    // Data from the req and put it in an array accessible to the main app.
    //console.log( req.body );
    logData(req);
    res.send(200, 'Save');
};

/*
 * POST Handler for /execute/ route of Activity.
 */
exports.execute = function (req, res) {

        var aArgs = req.body.inArguments;
        var oArgs = {};
        for (var i=0; i<aArgs.length; i++) {
            for (var key in aArgs[i]) {
                oArgs[key] = aArgs[i][key];
          console.log('oArgs[key]:'+oArgs[key]);
            }
        }
        console.log('>>>>> req.body: ' + req.body );
        console.log('>>>>> req.body.inArguments: ' + req.body.inArguments );

        var phone = oArgs.phone;
        var email = oArgs.email;

        console.log('>>>>> phone: ' + phone );
        console.log('>>>>> email: ' + email );

let data = ({
            "destinations": [{
                                "correlationId": "MyCorrelationId",
                                "destination": "5511*********"
                            },
                            {
                                "correlationId": "MyCorrelationId",
                                "destination": "5511*********"
                            }],
            "message": {
                "messageText": "<Message here>",
            },

         });

    axios({
      method: 'post',
      url: "https://api-messaging.movile.com/v1/whatsapp/send",
      data: data,
      headers: {'UserName': 'test@test.com.br',
                'AuthenticationToken': '_token_here_',
                'Content-Type': 'application/json'}
    }).then( (res) => {
        console.log("Success -->" , res);
    } )
    .catch( (error) => {
        console.log("Erro --> ", error);
    } );

};


/*
 * POST Handler for /publish/ route of Activity.
 */
exports.publish = function (req, res) {
   // alert("Publish");
    // Data from the req and put it in an array accessible to the main app.
    //console.log( req.body );

    logData(req);
    res.send(200, 'Publish');
};

/*
 * POST Handler for /validate/ route of Activity.
 */
exports.validate = function (req, res) {
   // alert("Validate");
    // Data from the req and put it in an array accessible to the main app.
    //console.log( req.body );
    logData(req);
    res.send(200, 'Validate');
};

I really needs to understand how to recover this data and make it work ... Sorry for any mistake.

1

In your customActivity;js, you should have a function save() where your payload is setup and ready to send it to your backend server.
If you want to retrieve data from a contact passing by your custom activity, you have to use special expressions like : {{Event.ID.column}} or {{Contact.Attribute.column}} the official doc.
When a contact will pass by your activity, those expressions will be evaluated for your contact so for example if you have a contact with a value : "example@gmail.com". You need to put in the payload something like this :

payload['arguments'].execute.inArguments = [{
        'emailAdress': "{{Event.ID-DE.EmailAdress}}"
    }];

So when your contact send his payload to the server, the expression will be in req.body.inArguments[0].emailAdress and be evaluated at : "example@gmail.com". If you need an example of working custom activity, I highly recommend to you this example of Markus Slabina which is great to understand the logic.

If you don't know where to have your dataExtension ID look at this exchange.
I hope this will help you

  • Thank you, Pierre! Really just needed to add this information in custom activity. I was able to retrieve the data from the platform and use them in my REST call. – Jeferson Silva Jul 19 '18 at 12:04
  • Np, I'm glad that it helped you :) – Pierre-Adrien Delisle Jul 19 '18 at 12:44

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.