I'm looking for a way to retrieve journey contact history – basically the same information that is on Journey Builder – History tab (Contact key, Journey Name, Activity name, Status, Timestamp) via SFMC API. I browsed the REST API documentation but couldn't find anything regarding getting that data. Has anyone ever done something like this and can push me in the right direction?
[SalesForce] way to retrieve Journey History for contact using REST API
Related Solutions
This might be of help - https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/datafolder.htm - I think it would be helpful if SFMC documentation would do some cross-linking on this topic.
Update
It has just occurred to me that it is possible to retrieve Email Subscriber Profile Attributes using Data Binding. I don't know why this didn't occur to me earlier. Simply use the string:
{{Contact.Attribute."Email Demographics".sub_id}}
Note that this will only work for required attributes. If sub_id
is nullable (that is, it does not contain a value for a Subscriber) then the Contact will fail at the Custom Activity. To overcome this, use block helpers to determine if there is a value and send a default value to the inArgument if it does not exist. For example:
{{#if Contact.Attribute."Email Demographics".sub_id}}
{{Contact.Attribute."Email Demographics".sub_id}}
{{#else}}
0
{{/if}}
Note that you will probably need to include this on a single line in your config.json file, I've beautified it for ease of reading. e.g. use:
{{#if Contact.Attribute."Email Demographics".sub_id}}{{Contact.Attribute."Email Demographics".sub_id}}{{#else}}0{{/if}}
Previous Answer
Including previous answer as it still may be valid for some use cases.
You will need to make a separate SOAP API request to get the Subscriber Profile Attribute to use in your Custom Activity.
For example, pass the Subscriber Key for the Contact using the data binding {{Contact.Key}}
as an inArgument, then get make a separate SOAP API request from your application using the request below.
You can copy and paste this working example into Postman.
You will need to set the {{soapEndPoint}}
to the appropriate SOAP Endpoint for your instance. Note that you can use the REST API to retrieve the SOAP endpoint for the instance where your application is installed on using the getEndpoints method.
POST {{soapEndPoint}}/Service.asmx
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">Retrieve</a:Action>
<a:MessageID>urn:uuid:7e0cca04-57bd-4481-864c-6ea8039d2ea0</a:MessageID>
<a:ReplyTo>
<a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">{{soapEndPoint}}/Service.asmx</a:To>
<fueloauth xmlns="http://exacttarget.com">{{accessToken}}</fueloauth>
</s:Header>
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<RetrieveRequest>
<ObjectType>Subscriber</ObjectType>
<Properties>ID</Properties>
<Filter xmlns:q1="http://exacttarget.com/wsdl/partnerAPI" xsi:type="q1:SimpleFilterPart">
<q1:Property>SubscriberKey</q1:Property>
<q1:SimpleOperator>equals</q1:SimpleOperator>
<q1:Value>{{subscriberKey}}</q1:Value>
</Filter>
</RetrieveRequest>
</RetrieveRequestMsg>
</s:Body>
</s:Envelope>
Note that by including ID
as a property, this will return all custom Subscriber Profile Attributes that you have added. You just need to parse the XML response to get the attribute that you need.
<soap:Body>
<RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<OverallStatus>OK</OverallStatus>
<RequestID>4d71d4e9-f954-45a7-8bd0-3153b44a07cf</RequestID>
<Results xsi:type="Subscriber">
<PartnerKey xsi:nil="true" />
<ID>2976505</ID>
<ObjectID xsi:nil="true" />
<Attributes>
<Name>sub_id</Name>
<Value>123</Value>
</Attributes>
</Results>
</RetrieveResponseMsg>
</soap:Body>
Best Answer
You can retrieve Journey History by POSTing to this endpoint /interaction/v1/interactions/traceevents/search
It is the same endpoint used in the History tab in Journey Builder.
Example of the request payload without any filter (apart from time)
Example of the request paypload with a filter on a journey
I suggest you use google developer tools (in Network tab) or any other monitoring tool to monitor the network traffic within the History tab of Journey Builder and learn more about this endpoint especially how to perform complex queries.
Please note that this is not officially available for use as it is not documented in the official documentation
[EDIT - 11/10/2017] You can now also use Journey Builder Data Views to retrieve Journey activity.
[EDIT - 31/12/2021] You can use POST /interaction/v1/interactions/journeyhistory/search or POST /interaction/v1/interactions/journeyhistory/filter or POST /interaction/v1/interactions/journeyhistory/download endpoints. For more information you can find all available endpoints by looking into the discovery endpoint GET /interaction/v1/rest