templates - Sendgrid 仅查找旧模板
问题描述
我正在为一个项目设置一个 SendGrid 客户端。当我尝试在 SendGrid 中访问我的模板时,它只返回旧模板,但完全忽略事务模板。我没有在网上找到任何关于这个特定问题的文档。
public async Task<Dictionary<string, string>> GetTemplateIdsByNameAsync()
{
//https://sendgrid.com/docs/API_Reference/Web_API_v3/Transactional_Templates/templates.html
//My client is being autheticated succesfully in the GetSendGridClient function
var client = GetSendGridClient();
//This function should get all the templates connected to my SendGrid account but only finds the legacy ones
var response = await client.RequestAsync(method: SendGrid.SendGridClient.Method.GET, urlPath:"templates");
ThrowExceptionIfStatusIsNotOk(response);
var content = await response.Body.ReadAsStringAsync();
var anonymousTemplatesObject = new { Templates = new[] { new { Id = "", Name = "" } } };
var templates = _genericJsonSerializer.DeserializeAnonymous(content, anonymousTemplatesObject);
return templates.Templates.ToDictionary(x => x.Name, x => x.Id);
}
我已经在这个问题上坐了一整天,但还没有找到解决方案
解决方案
虽然 SendGrid 尚未正确记录它,但正确的 API 调用语法是https://api.sendgrid.com/v3/templates?generations=legacy,dynamic
所以在这种情况下你需要使用https://api.sendgrid.com/v3/templates?generations=dynamic
有关更多背景信息,请参见此处:https ://github.com/sendgrid/sendgrid-csharp/issues/723
推荐阅读
- github - 如何在我的 Google Colab 笔记本中插入来自 Github 存储库的图像?
- javascript - 如何使用反应钩子在按钮单击时设置组件的当前状态
- angular - Jasmine-marble/createSpy - 无法读取未定义的属性“nativeElement”
- angular - DefaultHandlerExceptionResolver:已解决 [org.springframework.web.HttpMediaTypeNotSupportedException:不支持内容类型“文本/纯文本”]
- javascript - 在 Vue 之外使用 Buefy 组件
- java - JTable中的JComboBox不保存选择
- python - 大熊猫中的 df.iloc 函数不起作用
- php - 使用 cookie 时出现内部服务器错误 500
- android - Firestore 文档对象 (documentSnapshot) 到带有嵌套映射的 POJO
- node.js - Heroku 给了我一个 503 我不知道为什么