0

I am trying to inject contacts via journey rest api from cloud page. It seems to work fine if it is unique record, but if the contact already exists in a journey, the cloud page does not throw an error but no record is added to the DE and subsequently, no entry in the journey.

I've tried 2 different scenarios:

  1. Subkey and Date : composite keys
  2. No primary key (Subkey and email address is not nullable)

Journey setting is to allow re-entry anytime.

Is rest api journey entry admitting only one unique entry (per subscriber) expected behavior? If so, is there a workaround to allow multiple entries per subscriber?

Thanks in advance :)

2
  • Can you share entry DE fields definitions - types, nullable and primary key information? Jun 24, 2020 at 9:21
  • So I tried: Option 1 - No primary key://// SubscriberKey/ Text /50 ,, EmailAddress /EmailAddress/254 / nullable,, Option 2 - Composite keys//// SubscriberKey/ Text /50/Primary Key ,, EmailAddress /EmailAddress/254 / nullable,, Date/Date/ Primary key /////// Option 1 will insert contact once but no more after that. Option 2 will not insert any records at all but no error.
    – s3002068
    Jun 24, 2020 at 23:12

1 Answer 1

1

Perhaps you could try to add some more logic to your code, in which you first get a contact's exit status from a journey, if needed remove a contact from a journey, and then try to add him once again..

I wrote a quick sample:

function getStatus(token) {

    var config = {
        url : 'your rest base uri here' + "/interaction/v1/interactions/contactexit/status",
        contentType : "application/json",
        headerName : ["Authorization"],
        headerValue : ["Bearer " + token],
        payload : {
            ContactKey: 'pass in subscriber key',
            EventDefinitionKey: 'pass in key of journey here'
        }
    };

    var req = HTTP.Get(config.url, config.contentType, Stringify(config.payload), config.headerName, config.headerValue);
    
    var statusMessage = req[0].status[0].message;

    if (statusMessage == 'Exit process Completed.') {
        
        //make sure you delete contact from journey
        var deleteMessage = deleteContactFromJourney(token);

        //if everything went well you can add the contact to the journey.
        if (deleteMessage == 201) {
            addContactToJourney(token);
        } else {
            Write('error occured deleting contact.')
        }
        
    }
};

function deleteContactFromJourney(token) {

    var config = {
        url : 'your rest base uri here' + "/interaction/v1/interactions/contactexit",
        contentType : "application/json",
        headerName : ["Authorization"],
        headerValue : ["Bearer " + token],
        payload : {
            ContactKey: 'pass in subscriber key',
            EventDefinitionKey: 'pass in key of journey here'
        }
    };

    try {
        var req = HTTP.Post(config.url, config.contentType, Stringify(config.payload), config.headerName, config.headerValue);

        return req.Status;

    } catch (error) {
        return error;
    };


};

function addContactToJourney(token) {

    var config = {
        url : 'your rest base uri here' + "/interaction/v1/events",
        contentType : "application/json",
        headerName : ["Authorization"],
        headerValue : ["Bearer " + token],
        payload : {
            ContactKey: 'pass in subscriber key',
            EventDefinitionKey: 'pass in key of journey here',
            Data: {
                Attribute: "value"
            }
        }
    };

    try {
        var req = HTTP.Post(config.url, config.contentType, Stringify(config.payload), config.headerName, config.headerValue);
        Write(req.status);

    } catch (error) {

        Write("Error occurred:" + Stringify(error));

    };
};

Please be aware that I haven't included in the logic of how to obtain access token. But since you already were able to fire the journey builder API from a cloud page, I assume that you already managed to deal with this.

I haven't tested this code, but it should give you a direction to look for.

You must log in to answer this question.

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