2

I have an endpoint that is expecting data that is close to the below format (recipient object is required). I want to send this data after execution in my journey. The data is coming from my entry source (data extension). Here is documentation to the API I am wanting to send my POST to: API DOC

{
"campaign_id": "",
"recipient": {
    "first_name": "",
    "last_name": "",
    "company": "",
    "email": "",
    "address_1": "",
    "city": "",
    "state": "",
    "postal_code": "",
    "identifier": ""
}
}

In my config JSON, below is how I have successfully posted data to a postbin from my DE. Now, my issue is that the endpoint I want to use ONLY accepts the ABOVE data and nothing else. However, when I POST with the working format below it will come with additional data that is not accepted by the endpoint.

"arguments": {
"execute": {
  "inArguments": [
  "first_name": "{{Event.Entry-event-key.first_name}}",
  "last_name": "{{Event.Entry-event-key.last_name}}",
  "company": "{{Event.Entry-event-key.company}}",
  "email": ""{{Event.Entry-event-key.email}}""
  ],
  "outArguments": [],
  "url": "postbin endpoint url",
  "verb": "POST",
  "body": "",
  "header": "",
  "format": "json",
  "useJwt": false,
  "timeout": 10000
}
}

In addition, the endpoint also requires custom headers for access. Is it possible to do this kind of POST to an API from JB? One that only requires specific fields and nothing else?

If so, how can this be done? Is there a way to access the data I am pushing out of my custom activity? Clearly I am able to post it to postbin in the request body at this point. Maybe I need to push my DE data to an endpoint where I can again GET the data, rework it, and then POST it to the API in it's required format?

What is the best practice here?

1 Answer 1

4

I wouldn't go through the trouble of pushing this to a DE just so you can reformat your payload. Instead, create a save function on your client-side controller that will request the eventdefinitionkey and then format the payload to send to the back-end of your app on save:

connection.on("requestedTriggerEventDefinition", function(
    eventDefinitionModel
) {
    if (eventDefinitionModel) {
        definition = eventDefinitionModel;
        eventDefinitionKey = eventDefinitionModel.eventDefinitionKey;
    }
});

function save() {
    var campaign_id = $("#campaign_id").val();
    payload["arguments"].execute.inArguments = [{
        campaign_id: campaign_id,
        recipient: {
            first_name: "{{Event." + eventDefinitionKey + '."first_name"}}',
            last_name: "{{Event." + eventDefinitionKey + '."last_name"}}',
            company: "{{Event." + eventDefinitionKey + '."company"}}',
            email: "{{Event." + eventDefinitionKey + '."email"}}',
            address_1: "{{Event." + eventDefinitionKey + '."address_1"}}',
            city: "{{Event." + eventDefinitionKey + '."city"}}',
            state: "{{Event." + eventDefinitionKey + '."state"}}',
            postal_code: "{{Event." + eventDefinitionKey + '."postal_code"}}',
            identifier: "{{Event." + eventDefinitionKey + '."identifier"}}'
        }
    }];
    payload["metaData"].isConfigured = true;
    connection.trigger("updateActivity", payload);
}

Then, in your back-end processing, just decode your JWT to authenticate the request and grab your recipient object from the payload:

var args = decoded.inArguments[0];
var payloadToPostBin = args.recipient;
6
  • thank you for the great response. At the time of posting my save function looks almost identical to your example. That is actually exactly how I am currently assigning values from my DE. The only thing I didn't do was store the values in a recipient object but I will do exactly as your example moving forward. - You speak of sending the values to the backend of the app and working it from there. Here is where I would like additional guidance. How can I do this?
    – Aib Syed
    Commented Aug 28, 2020 at 4:35
  • Let's say my app URL is something like this: appurl.herokuapp.com - What would the endpoint be on execute to send to the backend, and should I create a new JS file to work the backend? (Sorry kind of new to working data like this, and I may be overlooking something completely trivial). Feel free to skip the jwt part if necessary.
    – Aib Syed
    Commented Aug 28, 2020 at 4:36
  • 1
    In your express logic, you should have a post method for each of the actions you want to take in your app (save/validate/publish/execute). This tells your application what file and function to run when a given action is triggered from SFMC. Locate the route to your execute function (what happens when a user record enters your activity step) and you can retrieve the payload values and format/make your API call from there. Commented Aug 28, 2020 at 4:42
  • 1
    Check out this repo: github.com/ExactTarget/journey-builder-custom-hello-world. Look at line 74 of the app.js file in the parent folder. This is what defines what to do when an action comes in from JB. For the execute method, notice that it's calling the path to file (defined at the top) and the execute function within that file.Navigate to that file path (routes/activity.js) and look for "exports.execute." Add your logic to grab the payload and call the API within that function as it will run on JB execution. Commented Aug 28, 2020 at 4:46
  • 1
    You'll still use those endpoints in your config file and within your package in SFMC, but refer to that post route for your own internal logic of how your application is going to process that data on a given event. Commented Aug 28, 2020 at 5:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .