1. I have successfully get access token via ssjs
  2. When passing it to POST /interaction/v1/events (https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/postEvent.htm) i'm getting error message "ContactKey is required"

SSJS Post Request:

var payload = {
            ContactKey: subscriberKey,
            EventDefinitionKey: EventDefinitionKey,
            EstablishContactKey: true, 
            Data: { 
                EmailAddress: emailAddress
        var url = 'https://www.exacttargetapis.com/interaction/v1/events';
        var auth = 'Bearer ' + accessToken;

        var req = new Script.Util.HttpRequest(url);
        req.emptyContentHandling = 0;
        req.retries = 2;
        req.continueOnError = true;
        req.contentType = "application/json"
        req.setHeader("Authorization", auth);
        req.method = "POST";
        req.postData = payload;

        var resp = req.send();

Sample Request:

    "Data": {

Sample response:

    "message": "ContactKey is required.",
    "errorcode": 10000,
    "documentation": ""

Why I'm getting that error message? Any help would be appreciated.

  • 1
    Not sure if that is the error, but if you want to use an ampscript variable in ssjs you need to use the GetValue Function to do so. – DonL Jun 14 at 14:00
  • Hi @DonL, thank you for your response. I updated the parameter i used for contact key. My script is written in ssjs. I hardcoded the parameters i used to test but still getting the error “ContactKey is required” – Feux Jun 14 at 18:20
  • Can you post your full script (no need for the auth token generation part)? – Jason Hanshaw Jun 14 at 19:52
  • @JasonHanshaw, please see above, added post script on my question. Thank you – Feux Jun 15 at 5:43
  • The code you provided is inconsistent. Does your SSJS POST Request Payload have double quotes in the JSON or not? If not, please add them. – DonL Jun 21 at 14:11

Use proper id posting request example here. {"EventDefinitionKey":"APIEvent-ba299b28-102a-d953-09bd-09bdf8e117e6","ContactKey":"ID601"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.