1

We've never used triggered sends before in Marketing Cloud and I'm trying to set up a test. I'm sending from Salesforce, so the callout is written in Apex. I've confirmed that the authentication is fine, so I'm skipping that piece of the code. (The triggered send definition is activated in Marketing Cloud as well.)

HttpRequest req = new HttpRequest();
req.setEndpoint('https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/myTriggeredSendDefinitionKey/send');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Authorization', 'Bearer '+accessToken);

Map<String,Object> to = new Map<String,Object>();
to.put('Address','myTestEmail@example.com');
to.put('SubscriberKey','myTestEmail@example.com');

Map<String,Object> options = new Map<String,Object>();
options.put('RequestType','SYNC');

Map<String,Object> body = new Map<String,Object>();
body.put('To',to);
body.put('Options',options);

String dataJSON = JSON.serialize(body);
req.setBody(dataJSON);

Http http = new Http();
HttpResponse res = http.send(req);
System.debug('response body: '+res.getStatusCode());

Debug:

|USER_DEBUG|[38]|DEBUG|response body: 404

The response body is empty for some reason, no exception/errors. Nothing is sent either. What am I doing wrong?

EDIT If it is relevant, these are the scopes for the installed package I'm using for authentication:

Email: Read, Write, Send

Interactions: Read, Write, Execute

List And Subscribers: Read, Write

Data Extensions: Write

  • What HTTP Status code do you receive in your response? Is the Status of your Triggered Send 'Running' (note you need to publish and then start your Triggered Send). Did you replace myTriggeredSendDefinitionKey with your actual key? – Eliot Harper Jun 17 '18 at 3:26
  • @EliotHarper It's returning a 404 (will add to the post). Yes, it is published & started. I just paused, re-published, and restarted, no effect on outcome. And yes, I just put that into my sample code to remove the actual key for StackExchange. – Mike Jun 17 '18 at 5:19
  • I've just found another SE post saying that "key:" is required in the endpoint. When I rewrite as [...]/messageDefinitionSends/key:myTriggeredSendDefinitionKey/send, I get a 202. – Mike Jun 17 '18 at 5:26
  • I don't see from name/ address which I believe are required for the call. – Gortonington Jun 17 '18 at 11:03
  • Also the url with key I believe should be /key:yourTriggerKey/ – Gortonington Jun 17 '18 at 11:05
4

Sorry can't use comments yet.
As per official documentation:

  1. "key:" in the endpoint should be used for ExternalKey, otherwise ObjectId should be used.
  2. From name not required, thats why Send Classification is required in Triggered Send definition.
  3. Status 202 mean that send was queued and will be completed soon.
  4. Check your response to get additional information

Working Example:
Request:

POST /messaging/v1/messageDefinitionSends/key:test02TS/send HTTP/1.1
Host: www.exacttargetapis.com
Authorization: Bearer 4mynNSaOYlaeZod2E5Uw34g4
Content-Type: application/json
Cache-Control: no-cache

{
    "To": {
        "Address": "test02@gmail.com",
        "SubscriberKey": "test02@gmail.com"
    }
}

Response:

{
    "requestId": "70f0b456-1f96-4b35-b101-8e751b7c1a52",
    "responses": [
        {
            "recipientSendId": "70f0b456-1f96-4b35-b101-8e751b7c1a52",
            "hasErrors": false,
            "messages": [
                "Queued"
            ]
        }
    ]
}
  • Although it’s probably expired now, I wouldn’t recommend posting your access token on here – Samuel Dare Jun 17 '18 at 20:50
  • 1
    @Data_Kid no worries its a fake token – Ros Haitovich Jun 18 '18 at 5:30
1

As you the HTTP status code infers, (and as @Gornington commented) your endpoint is incorrect. You are missing the key: prefix.

UPDATE: after further tests, the from object is not required in the payload, but if included, it will override the sender profile used in the triggered send.

Here is some modified code:

HttpRequest req = new HttpRequest();
req.setEndpoint('https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/key:myTriggeredSendDefinitionKey/send');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Authorization', 'Bearer '+accessToken);

Map<String,Object> from = new Map<String,Object>();
from.put('Address','noreply@mydomain.com');
from.put('Name','My Company Name Here');

Map<String,Object> to = new Map<String,Object>();
to.put('Address','myTestEmail@example.com');
to.put('SubscriberKey','myTestEmail@example.com');

Map<String,Object> options = new Map<String,Object>();
options.put('RequestType','SYNC');

Map<String,Object> body = new Map<String,Object>();
body.put('From',from);
body.put('To',to);
body.put('Options',options);

String dataJSON = JSON.serialize(body);
req.setBody(dataJSON);

Http http = new Http();
HttpResponse res = http.send(req);
System.debug('response body: '+res.getStatusCode());

Note that myTriggeredSendDefinitionKey is the key assigned to the Triggered Send.

Also ensure that noreply@mydomain.com is an email domain that relates to your SAP domain (or a private domain) associated with your account.

  • Thanks, according to the documentation, "from" is not required: developer.salesforce.com/docs/…. It's defined in the Send Classification (and is associated to an SAP domain). Adding the "key:" string results in the email now coming through. – Mike Jun 17 '18 at 16:37
  • 1
    Oh, you're right. I just tried removing the from object, and the email sent. It looks like the from object just overrides the sender profile assigned to the triggered send. Anyway, when you send, do you see the email in the triggered send queue, and does it then increment the 'completed' queue? – Eliot Harper Jun 17 '18 at 16:58

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.