我一直读到Salesforce (我对这个第三方平台非常陌生)有一个FUEL SDK,可以用它代替版本(使用HttpClient -- REST而不是SOAP)。
如果使用FUEL SDK是请求Salesforce端点的唯一方法,请纠正我。目前,我正在尝试使用HttpClient访问ExactTarget的API端点。以下是我根据以下内容编写代码的教程:
通缉结果:
能够根据Triggered Send内部的模板请求一个ExactTarget电子邮件。
问题:
-- Salesforce端点--连续返回404。我能够成功地接收授权令牌。为了简洁起见,省略了GetAccessToken方法。
https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/key:MyExternalKey/send
我不明白为什么对POST的第二个//www.exacttargetapis.com/.....请求返回一个404,但授权工作。这使我相信,我不必使用FUEL SDK来完成触发欢迎电子邮件的工作。
代码:
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;
}我还尝试使用以下方法使用Advanced REST Client:
网址: https://www.exacttargetapis.com/messaging/v1/messageDefinitionSends/key:MyExternalKey/send
POST
原始头:
原始有效载荷:
{
"From": {
"Address": "code@exacttarget.com",
"Name": "Code@"
},
"To": {
"Address": "example@example.com",
"SubscriberKey": "example@example.com",
"ContactAttributes": {
"SubscriberAttributes": {
"Region": "West",
"City": "Indianapolis",
"State": "IN"
}
}
},
"OPTIONS": {
"RequestType": "ASYNC"
}
}发布于 2016-10-06 17:18:54
问题是我在AppCenter中的应用程序指向了MarketingCloud =(
https://stackoverflow.com/questions/39855368
复制相似问题