I'm trying to trigger a journey via the API and I am getting a "500 Internal Server Error". This is the processing page for a custom profile center built on CloudPages.
Here is my code:
%%[
/* Get Subscribers Email Address */
SET @email = RequestParameter("EmailAddress")
/* Get Access token using API creds */
Var @body, @callstatus, @response
Set @body = '{"clientId": "xxxxxx", "clientSecret": "yyyyyy"}'
HTTPPost2("https://auth.exacttargetapis.com/v1/requestToken", "application/json", @body, True, @callstatus, @response)
]%%
<script runat="server">
// Load response into SSJS for parsing
Platform.Load("Core", "1")
// get JSON from callstatus
var callstatus = Variable.GetValue("@callstatus");
// Parse the string to JSON
callstatus = Platform.Function.ParseJSON(callstatus);
// Get Access Token
Variable.SetValue("@access_token",'BEARER ' + callstatus.accessToken);
</script>
%%[
/* Trigger the Journey via API event */
Set @body = '{"ContactKey": @email, "EventDefinitionKey":"APIEvent-ad292469-4d77-17a9-e56d-b791b29b8b95", "EstablishContactKey": true, "Data": {"EmailAddress":@email}}'
HTTPPost2("https://auth.exacttargetapis.com/interaction/v1/events", "application/json", @body, True, @callstatus, @response, 'Authorization', @access_token)
]%%
Honestly I'm not sure what "ContactKey"
needs to be and if I even need the "Data"
parameter at all. By the time this triggers the Data Extension already has the user's profile filled out.
Also I am getting the @access_token
correctly so the issue lies somewhere in the second HTTPPost2
.
Any help greatly appreciated!