我在使用SendGrid API时遇到了一个奇怪的问题。基本上,我可以执行某些API调用,而其他一些则返回403错误。
我可以发一封电子邮件:
$email = new \SendGrid\Mail\Mail();
$email->setFrom("myfrom@myurl.net", "NAMEFROM");
$email->setSubject("Sending with SendGrid is Fun");
$email->addTo("myfrom@myurl.net", "NAMEFROM");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
"text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
$response = $sendgrid->send($email);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}但我无法作为竞选活动发送大量电子邮件:
$request_body = json_decode('{
"id": <DATA HIDDEN>,
"title": "May Newsletter",
"subject": "New Products for Summer!",
"sender_id": <DATA HIDDEN>,
"list_ids": [
"<DATA HIDDEN>"
],
"html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
"plain_content": "Check out our summer line!",
}');
$sg = new SendGrid(config('services.extra.SENDGRID_API_KEY'));
$response = $sg->client->campaigns()->post($request_body);此呼叫返回403“消息”:“禁止访问”。没有任何其他迹象。
甚至API也会调用以下内容:
https://api.sendgrid.com/v3/senders/<data hidden>
https://api.sendgrid.com/v3/senders返回403。
我有一个免费的计划和一个经过验证的电子邮件地址(“从地址”)。我生成的所有令牌都具有“完全”权限集。
我还没有读过任何关于文档中的价格计划(免费/付费)的API可访问性的文章,但是,我想知道是否有人知道什么。
任何帮助都是非常感谢的。
发布于 2022-04-20 23:01:56
Email API和市场营销活动是两种不同的产品(参见定价页面上的两个不同的选项卡)。您可以在一个帐户内使用这两个,您只需要激活两个产品。我认为您需要访问您的客户设置并激活营销活动产品,然后您的API请求就会成功。
发布于 2022-09-14 01:55:49
当我创建API键时,它以非常有限的权限创建它。然后,您需要去启用密钥上的权限。我不断地得到403个错误,当我最终为我使用的API添加了权限时,它们就开始工作了。
https://stackoverflow.com/questions/71938370
复制相似问题