4

I am trying to fire an ExactTarget triggered email using the Salesforce developer console. I am now getting the error "Problem initating message send during deserialization of JSON payload"

Http http2 = new Http();  
HttpRequest req2 = new HttpRequest();
req2.setMethod('POST');
  req2.setEndpoint('https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/b315a0e9-3618-e411-b6d6-b4b52f5cc7b0/send?access_token='+accessToken);
  req.setHeader('Content-Type', 'application/json');


 String SendId='"Address to send to"'   ;
 String MyEmail='"My Email"';
 String MyName='"My Name"';

  req2.setBody('To=' + SendId +'&From=' +MyEmail +'&From_Name=' +MyName);

 HttpResponse res2 = http.send(req2);
System.debug('Fulfillment service on Triggered Send '+ res2.getBody());

I believe my issue is setting up the JSON string to pass into the body for ET. Does anybody know how to fix this?

1 Answer 1

0

The Body of the request in the question doesn't appear to be valid JSON.

From the POST /messageDefinitionSends it should look more like:

{
    "From": {
        "Address": "[email protected]",
        "Name": "Code@"
    },
    "To": {
        "Address": "[email protected]",
        "SubscriberKey": "[email protected]",
        "ContactAttributes": {
            "SubscriberAttributes": {
                "Region": "West",
                "City": "Indianapolis",
                "State": "IN"
            }
        }
    }
}

The JSONGenerator should help in creating this for you. As a start:

JSONGenerator gen = JSON.createGenerator(true);

gen.writeStartObject();

gen.writeFieldName('From');

gen.writeStartObject();
gen.writeStringField('Address', MyEmail);
gen.writeStringField('Name', MyName);
gen.writeEndObject();

gen.writeFieldName('To');
gen.writeStartObject();
gen.writeStringField('Address', SendId);
// You might need to set the SubscriberKey etc... here?
gen.writeEndObject();

String pretty = gen.getAsString();
System.debug(pretty);

req2.setBody(pretty);
5
  • Thank you so much, I added your snippet of code, as well as the subscriberkey section. However I am now getting the error Fulfillment service on Triggered Send {"requestId":"461fd7e9-ac39-4cfa-b67f-6414d71eeb4f","responses":[{"recipientSendId":"","hasErrors":true,"messages":["InvalidOrMissingTo"]}]} What is that coming from? Commented Aug 6, 2014 at 15:37
  • @BalazsHoranyi Is the value in the SendId a valid email address? Commented Aug 6, 2014 at 23:23
  • @ DanielBallinger, Yes it is a valid email address. Commented Aug 6, 2014 at 23:37
  • @BalazsHoranyi I'm not sure how to fix the new error. Maybe try sending a hardcoded JSON string through first and then seeing if you can automate it after that. Was the messageDefinitionSends documentation I linked to the correct API method? Commented Aug 7, 2014 at 1:03
  • Actually came down to a typo in my code. req.setHeader needed to be req2.setHeader. Thanks for all the help Commented Aug 8, 2014 at 18:14

You must log in to answer this question.

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