2
  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:

{
    "ContactKey":"test@email.com",
    "EventDefinitionKey":t"APIEvent-xxx",
    "Data": {
        "field1":"value1" 
    }
}

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 '19 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 '19 at 18:20
  • Can you post your full script (no need for the auth token generation part)? – Jason Hanshaw Jun 14 '19 at 19:52
  • @JasonHanshaw, please see above, added post script on my question. Thank you – Feux Jun 15 '19 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 '19 at 14:11
1

What is the content type of your header? It should be 'application/json'. A different type will cause Salesforce to return this misleading error message.

  • I forgot to set Content-type -> Application-json on header. Great man! – Átila Castro Alves Aug 5 '20 at 19:42
0

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

0

Your json request is not in valid json format. Salesforce is trying to parse what you're providing, ContactKey is just the first thing - it's not where the actual problem is. Display or log your json in the console, copy it, download the free Postman HTTP application if you don't already have it, paste it in the 'Body' tab in Postman, and see if Postman shows an error. See if you can submit your request in Postman.

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.