我一直在尝试使用API检索SendGrid事务模板列表。我正在使用正确的API密钥并获取一个空数组,而我的SendGrid帐户中存在大约5个事务模板。以下是回复:
{
"templates": []
}
任何猜测可能是错的?
任何猜测可能是错的?
是的,他们的文件可能是!
我也坚持了这个问题,一旦我打开devtools并看到他们如何从UI请求他们自己的API,我终于设法解决了它。长话短说 - 一个必须传递额外的generations=dynamic
查询参数。这是我使用的C#代码:
var client = new SendGridClient("key");
var response = await client.RequestAsync(
SendGridClient.Method.GET,
urlPath: "/templates",
queryParams: "{\"generations\": \"dynamic\"}");
使用Api 7.3.0 PHP
require("../../sendgrid-php.php");
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
#Comma-delimited list specifying which generations of templates to return. Options are legacy, dynamic or legacy,dynamic
$query_params = json_decode('{"generations": "legacy,dynamic"}');
try {
#$response = $sg->client->templates()->get();
$response = $sg->client->templates()->get(null, $query_params);
echo $response->body();
exit;
} catch (Exception $e) {
echo '{"error":"Caught exception: '. $e->getMessage().'"}';
}