0

I've read along the way that Salesforce (I'm extremely new to this 3rd party platform) has a FUEL SDK which one can use instead of the version (using HttpClient -- REST instead of SOAP).

Please correct me if using FUEL SDK is the only way to go about requesting Salesforce's endpoints. These are the tutorials I've been basing my code off of:

Wanted Result:

To be able to request a Triggered Send email based off a template inside of ExactTarget.

Problem:

The Salesforce endpoint continuously returns a 404. I am able to receive the authorization token successfully. The GetAccessToken method is omitted for brevity

https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/key:MyExternalKey/send

I do not understand why the 2nd POST request to //www.exacttargetapis.com/..... returns a 404 but the authorization works. This leads me to believe that I do not have to use the FUEL SDK to accomplish triggering a welcome email.


Code:

    private const string requestTokenUrl = "https://auth.exacttargetapis.com/v1/requestToken";
    private const string messagingSendUrl = "https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends";
    private string exactTargetClientId = ConfigurationManager.AppSettings["ExactTargetClientId"];
    private string exactTargetClientSecret = ConfigurationManager.AppSettings["ExactTargetClientSecret"];

    private string TriggerEmail(User model, string dbName)
    {
        var etExternalKeyAppSetting = ConfigurationManager.AppSettings.AllKeys.FirstOrDefault(x => x.Equals(dbName));
        if (etExternalKeyAppSetting != null)
        {
            string etExternalKey = ConfigurationManager.AppSettings[etExternalKeyAppSetting];

            HttpClient client = new HttpClient
            {
                BaseAddress = new Uri(string.Format(@"{0}/key:{1}/send", messagingSendUrl, etExternalKey)),
                DefaultRequestHeaders =
                {
                    Authorization = new AuthenticationHeaderValue("Bearer", this.GetAccessToken())
                }
            };

            try
            {
                var postData = this.CreateExactTargetPostData(model.Email, etExternalKey);
                var response = client.PostAsync(client.BaseAddress
                                                , new StringContent(JsonConvert.SerializeObject(postData).ToString()
                                                                        , Encoding.UTF8
                                                                        , "application/json")).Result;

                // get triggered email response
                if (response.IsSuccessStatusCode)
                {
                    dynamic result = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }

        return "testing";
    }

    private object CreateExactTargetPostData(string email, string extKey)
    {

        var fromData = new
        {
            Address = ConfigurationManager.AppSettings["AwsSenderEmail"],
            Name = "Test"
        };

        var subscriberAttributes = new { };

        var contactAttributes = new
        {
            SubscriberAttributes = subscriberAttributes
        };

        var toData = new
        {
            Address = email,
            //SubscriberKey = extKey,
            //ContactAttributes = contactAttributes
        };

        var postData = new
        {
            From = fromData,
            To = toData
        };

        return postData;
    }
  • That endpoint is correct so not sure why you would get a 404 error. However, silly question: are you replacing the MyExternalKey value with the numeric External Key of the Triggered Send? Have you published and started the triggered send? – Eliot Harper Oct 5 '16 at 5:02
  • @EliotHarper yes, the "MyExternalKey" is a 5 digit number, in my case, located on the actual triggered send email (I believe the field is listed as "External Key" in Marketing Cloud). I have published the send, but I don't know about starting it, I'll have to check – Rob Scott Oct 5 '16 at 13:58
  • Check the send has started by selecting it from the Triggered Sends page. If you see 'Start/Restart' is disabled, then it's started. – Eliot Harper Oct 5 '16 at 18:27
1

I can reproduce the 404 error that you report, but only if a published (and running) Triggered Send is not available with the External Key in your URL parameter. Here's things I would check:

  1. Select the send is running by selecting it from the Triggered Sends page. If you see 'Start/Restart' is disabled, then it's running.
  2. Check the credentials that you used to create the App in AppCenter. Ensure that the selected Business Unit that you used when created the App matches the Business Unit where the Triggered Send resides. You can't see this, so you may need to create a new API Integration app to check this — refer to screenshot below.
  3. Check that you have app permissions (in your App Center App) to send Emails; ensure that 'Send' is selected in the Email option (although I'd expect it to throw a 403 error rather than 404).

select BU

  • A big thanks my friend. The AppCenter was the issue, I had applied the key to the incorrect login. – Another question. I received a response that has 'queued`. Does this not automatically send the email? Do I need to call another API endpoint? In the TriggeredSends section in MarketingCloud (UI), the # of queued emails says 0. – Rob Scott Oct 6 '16 at 16:53
  • This places the email in a queue and schedules it to send. Typically this takes anywhere from 30 secs to 2 mins. You can preview the status from the Triggered Sends page; when the message is sent, the queue number will be reset to 0 and the sent number will increment. If it's not incrementing, is the error count increasing? – Eliot Harper Oct 6 '16 at 17:09
  • 1
    I just checked it and it started incrementing the Queue appropriately. Thanks again! – Rob Scott Oct 6 '16 at 17:17

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.