[SalesForce] Exact Target Triggered Send using salesforce APEX

I am trying to send an Exacttarget triggered email using the Salesforce APEX developer console.
In the end I would like a member update on Salesforce to send a triggered email from Exacttarget. I have been trying to use the Rest Route https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/key:{customerKey}/send
but to no luck. I am working in a sandbox account on salesforce and have api privileges on Exacttarget. Does anyone an example code of doing something similar?
Thanks for any and all help.

The Snippet of the code that I am using to try sending a triggered email from Salesforce is

  global class TriggeredSend {
   @future (callout=true)
  public static void send(){

     Http h = new Http();  
     HttpRequest req = new HttpRequest();
     req.setMethod('POST');
          req.setEndpoint('https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/b315a0e9-3618-e411-b6d6-b4b52f5cc7b0/send');


     // Specify the required user name and password to access the endpoint
     // As well as the header and header information
      String username = '***';
     String password = '***!';


     Blob headerValue = Blob.valueOf(username + ':' + password);
     String authorizationHeader = 'BASIC ' +
     EncodingUtil.base64Encode(headerValue);
     req.setHeader('Authorization', authorizationHeader);

     // Create a new http object to send the request object
     // A response object is generated as a result of the request  

     Http http = new Http();
     HTTPResponse res = http.send(req);
     System.debug('Fulfillment service returned '+ res.getBody());


   // Examine the status code from the HTTPResponse
   // If status code != 200, write debugging information, done
    if (res.getStatusCode() != 200) {
    System.debug('Error from ' + req.getEndpoint() + ' : ' +
    res.getStatusCode() + ' ' + res.getStatus());
 }
       else{System.debug('Success!');}
   }
 }
 }

Where b315a0e9-3618-e411-b6d6-b4b52f5cc7b0 is the object id that was created when I defined a new triggeredsend definition using php code. I am receiving a 401 error (unauthorized), which leads me to believe that the URL I am using is incorrect, but do not know why.

Best Answer

It looks like the request is attempting to pass a username and password. With ExactTarget REST APIs, it requires following an OAuth flow in order to get a token which is passed in the request. I would check out https://code.exacttarget.com/apis-sdks/rest-api/using-app-center-to-get-an-api-key.html first in order to get a set of keys, then https://code.exacttarget.com/apis-sdks/rest-api/using-the-api-key-to-authenticate-api-calls.html to explain how to pass a token to the service you are attempting to use.

Related Topic