So many people have wanted to check the status or gather relevant Journey information from those they push in. This endpoint may not be the most efficient way, but currently it is one of the easiest ways to get the context and status of each subscriber entered into a Journey.

An undocumented endpoint in the interaction category allows you to grab Journey History – which includes the id, mid, eventid, definitionid, definitionname, eventname, contactkey, transactiontime, and status. Which would provide ample information for a quick ‘dashboard’ to check on Journey entry health.

Of course there are a couple ‘eccentricities’ to this endpoint, so there will be caveats and ‘hacks’ needed to get this working right. First note is that there is no filter ability nor sorting (but by default it orders by transactionTime ASC).

To get around this, I would utilize some SSJS (or your server-side language of choice if using a 3rd Party API call) to kinda manipulate this into a more feasable and reusable resource.

First part is to make a call to the API to get yourself an oAuth token.

function generateToken(clientId, clientSecret, mid, authURL, version) {
  
  if (version = 2) {
  	var versionEndpoint = '/v2/token'

  	var authJSON = {
	"grant_type": "client_credentials",
	"client_id": clientId,
	"client_secret": clientSecret,
	"account_id": mid
	}
  } else {
  	var versionEndpoint = '/v1/requestToken'

  	  var authJSON = {
    "clientId": clientId,
    "clientSecret": clientSecret
  }
  }

  var authUrl = authURL + versionEndpoint;
  var contentType = 'application/json';
  var authPayload = Platform.Function.Stringify(authJSON);

  var accessTokenResult = HTTP.Post(authUrl, contentType, authPayload);

  var statusCode = accessTokenResult["StatusCode"];
  var response = accessTokenResult["Response"][0];

  if(version = 2) {
  	  var accessToken = Platform.Function.ParseJSON(response).access_token;
  } else {
  	  var accessToken = Platform.Function.ParseJSON(response).accessToken;
  }

  return accessToken;
}

This will return the raw token, you would then need to prepend ‘Bearer ‘ in front of it for it to be acceptable for future REST API calls

Once you have your token, you now will hit the new Journey History endpoint to get the array for records in past 30 days.

function journeyHistoryReturn(authToken,endPointURL,page,pageSize) {
	var endPoint = endPointURL + '/interaction/v1/interactions/journeyhistory/search?$page=' + page + '&$pageSize=' + pageSize;
	var contentType = 'application/json';
	var payload = '';
	var headers = ['Authorization'];
	var headervalues = [authToken];

	var results = HTTP.Post(endPoint, contentType, payload, headers, headervalues);


	return results.Response;
}

This will then return an array containing a nested array with all the records. So in order to access it, you will need to parse the nested array into a JSON as SFMC stores this nested array as a string. Something like: var items = Platform.Function.ParseJSON(jHReturn[0]).items

From there you would just need to upsert these records into the DE you want to contain your history:

function journeyHistoryUpsert(items, deUpsert) {

	var successful = 0

	for(i=0; i < items.length; i++) {

		var id 		     	= items[i].id;
		var mid 		    = items[i].mid; 
		var eventId 		= items[i].eventId;
		var definitionId 	= items[i].definitionId;
		var definitionName 	= items[i].definitionName;
		var eventName 		= items[i].eventName;
		var contactKey 		= items[i].contactKey;
		var transactionTime = items[i].transactionTime;
		var status 		    = items[i].status;

		var filterNames = ['ID','MID','ContactKey','EventID','DefinitionID','DefinitionName','EventName','TransactionTime','Status']]
		var filterValues = [id,mid,contactKey,eventId,definitionId,definitionName,eventName,transactionTime,status]

		var columnNames = ['LastUpdated']
		var columnValues = [Now()]

		var journeyRows = Platform.Function.UpsertData(deUpsert,filterNames,filterValues,columnNames,columnValues)
		if(journeyRows = 1) { successful += 1 }
	}

	return successful;
}

This will then upsert the records into a DE.

Please note that the DE should have ALL the fields be the primary keys except for a single field ‘LastUpdated’ which will just show the last time that the record was touched via this process. I have all the others be primary keys as each value returned is unique in one way or another and in order to properly document, we need these to all exist within the DE.

This Data Extension will then be a ‘go to’ resource for Journey History reporting and tracking. Including tracking entry event status and more.

Tags: , , , , , , , , , , , , , ,
Subscribe
Notify of
guest
9 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Carlos
Carlos
5 years ago

Great article!

Victor
Victor
4 years ago

Hi! That’s a really useful article. But there is one major issue that wasn’t addressed: How to get more than 10000 records this way. There is an error when you try to reach page 11 with pageSize 1000: “Record access cannot exceed 10,000th item.”
We have smth like 1 million records. Is there any way to loop through them to get all of them into DE?

Alan
Alan
Reply to  Victor
3 years ago

Did you solve the problem? I´m getting the same error as you

PK
PK
Reply to  Alan
2 years ago

is it resolved? can someone post the resolution?

Khoa Nguyen
Khoa Nguyen
Reply to  Victor
1 year ago
Stam
Stam
3 years ago

You have error in code: “defintionName” instead of “definitionName”

Thiago
Thiago
10 months ago

var headervalues = [‘Bearer ‘ + authToken];

Carl S
Carl S
8 months ago

Anyone know if the journey history endpoint was deprecated? Using Postman, I’m just getting back a 404 – Not Found, and trying to figure out if it’s my Postman config or something else. Trying to use

https://{{et_subdomain}}.rest.marketingcloudapis.com/interaction/v1/interactions/journeyhistory/search

(and yes, et_subdomain is set… I’m able to hit other endpoints with no issues)