2

I am sending an exact target triggered email using the salesforce Apex developer. However when a member's name does not already exist on the ET side I do not know how to pass that information to ET. Right now I am passing the "Sent To" email via a JSON generator pulled from a campaign member email, and all that works out fine, it creates a new subscriber on the ET side and sends them an email, but it does not fill out the information for the name. I need this to be filled out so that the email can be customized. My current code looks like

 Http http2 = new Http();  
     HttpRequest req2 = new HttpRequest();
     req2.setMethod('POST');
     req2.setEndpoint('https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/key:Braz    ilAppRecieved/send?access_token='+accessToken);
      req2.setHeader('Content-Type', 'application/json');

    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);
gen.writeStringField('SubscriberKey',SendId);
gen.writeEndObject();

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

req2.setBody(pretty);



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

I managed to figure it out. You can pass subscriber attributes like so

gen.writeFieldName('To');
gen.writeStartObject();
    gen.writeStringField('Address',SendId);
    gen.writeStringField('SubscriberKey',SendId);
        gen.writeFieldName('ContactAttributes'); 
        gen.writeStartObject();
        gen.writeFieldName('SubscriberAttributes');
          gen.writeStartObject();
            gen.writeStringField('FirstName',FirstName);
            gen.writeStringField('LastName',LastName);
         gen.writeEndObject();  
gen.writeEndObject();
0

correction:

gen.writeStringField('Address',SendId); should be
gen.writeStringField('Address','someemail@domain.com');

----
gen.writeFieldName('To');
gen.writeStartObject();
    gen.writeStringField('Address','someemail@domain.com');
    gen.writeStringField('SubscriberKey',SendId);
        gen.writeFieldName('ContactAttributes'); 
        gen.writeStartObject();
        gen.writeFieldName('SubscriberAttributes');
          gen.writeStartObject();
            gen.writeStringField('FirstName',FirstName);
            gen.writeStringField('LastName',LastName);
         gen.writeEndObject();  
gen.writeEndObject();
1
  • Would you like to explain in few line what you have done?
    – Ashwani
    Aug 19 '15 at 19:12

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.