0

I'm very new to SFMC and I'm building custom activity in the journey builder, I facing issues in reading the data from data extension. My goal is to read de data to execute API. So, I've performed the following steps:

  1. Created the Data Extension and named SN_New_test_check [![DE name and data][1]][1]

  2. Created Attribute group [![Attribute group and DE relation][2]][2]

  3. Contact Key field to my Data Extension's CCID field

  4. Below is the "arguments" node in my config.json:

    "arguments": { "execute": { "inArguments":[ { "firstName": "{{Contact.Attribute.SN_New_test_check.FirstName}}"
    }
    ], "outArguments": [], "url": "https://{HostName}.herokuapp.com/journeybuilder/execute", "verb": "POST", "body": "", "header": "", "format": "json", "useJwt": true, "timeout": 10000 } }

Now I wanted to understand, how to take firstName value in my,

app.post('/journeybuilder/execute/', activity.execute ); method. (this is my app.js)
exports.execute = function (req, res) {

// This is my activity.js // Here I want firstName values, how do I take // This method called when we activate journey }

0

Assuming you are doing the data binding right, the next thing to do is decoding the token (as you are using JWT according to your config.json) in your handler method for the "execute"-route. After decoding it, the firstName is present in the resulting javascript object under the inArguments-property: yourdecodedjson.inArguments.firstName

It looks like you are using the Node.js express library, so you could use the body-parser and jsonwebtoken packages in order to parse/decode application/jwt.

You can find example code on how to do this on my github repository Salesforce Marketing Cloud - Service Cloud Custom Split Activity. The relevant files are backend/server.js and backend/lib/jwt.js.

Some of the most relevant code snippets required in the custom activity's backend:

Register middleware that parses the request payload:

app.use(require('body-parser').raw({
    type: 'application/jwt'
}));

Handler method for verifying and decoding the JWT (my backend/lib/jwt.js, which utilizes jsonwebtoken module):

'use strict';

module.exports = (body, secret, cb) => {
    if (!body) {
        return cb(new Error('invalid jwtdata'));
    }

    require('jsonwebtoken').verify(body.toString('utf8'), secret, {
        algorithm: 'HS256'
    }, cb);
};

Further information:

| improve this answer | |
  • but in your config.json, "inArguments": [] is empty, you are not reading anything from DE. – Sunil Nagargoje Mar 5 at 11:43
  • That’s because in my example the inArguments are dynamically filled based on the configuration of the activity in the config wizard. This can be seen in the customActivity.js on lines 111-113. But decoding and using the data works the same, so this shouldn’t bother you much. – Markus Slabina Mar 5 at 11:49
  • Txs got it, How to get theses (decoded.inArguments and decoded.inArguments[0]) values in string – Sunil Nagargoje Mar 5 at 12:19
  • I want values in string from above object i.e. decoded.inArguments – Sunil Nagargoje Mar 5 at 12:21
  • As already mentioned in my post it will be accessible using decoded.inArguments.firstName in your case. If you did the binding right and the value is a string then it also will be in that variable. For further details please refer to the readme and the code on github. – Markus Slabina Mar 5 at 12:26

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.