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);

/* 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!

1 Answer 1



You need to build the body-string using the Concat-function as otherwise you'd have the string @email inside your JSON instead of a property with the value of the @email-variable. So this could be done like this:

Set @body = Concat('{"ContactKey": "', @email, '", "EventDefinitionKey":"APIEvent-ad292469-4d77-17a9-e56d-b791b29b8b95", "EstablishContactKey": true, "Data": {"EmailAddress": "', @email, '}}'


There is no general answer on what needs to be the ContactKey as this depends on the setup of your marketing cloud instance. Most of the time this is set up to use an identifying information on your subscriber. So this could either be an email address or an internal ID you/your customer manages (like the ContactId from Salesforce Service Cloud if this is connected to Marketing Cloud).

How to check what you need to supply as Contact Key: Go to Email Studio > Subscribers > All Subscribers and check the column Subscriber Key. The value supplied there for your subscriber needs to be your Contact Key.

Further documentation:

  • Great! So I've checked and the "Contact Key" is the email so that is good to go. I've set the @body variable as follows: Set @body = Concat('{"ContactKey": "', @email, '", "EventDefinitionKey":"APIEvent-ad292469-4d77-17a9-e56d-b791b29b8b95", "EstablishContactKey": "true", "Data": {"EmailAddress": "', @email, '"}}') ... I am still getting a 500 error. Is my http2 call wrong?
    – DigitalMC
    Mar 27, 2018 at 16:40
  • Nevermind I got it! The issue was the subscriber already existed on the Data Extension so the API was erroring. Thanks so much!
    – DigitalMC
    Mar 27, 2018 at 21:53

You must log in to answer this question.

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