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.