|
通过托管 OAuth 认证访问 SendGrid API。发送事务性邮件和营销邮件,管理联系人、模板、屏蔽列表,并分析邮件性能。
bash
https://gateway.maton.ai/sendgrid/{native-api-path}
将 {native-api-path} 替换为实际的 SendGrid API 端点路径。网关将请求代理到 api.sendgrid.com 并自动注入您的 OAuth 令牌。
所有请求都需要在 Authorization 头中包含 Maton API 密钥:
Authorization: Bearer $MATONAPIKEY
环境变量: 将您的 API 密钥设置为 MATONAPIKEY:
bash
export MATONAPIKEY=YOURAPIKEY
在 https://ctrl.maton.ai 管理您的 SendGrid OAuth 连接。
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections?app=sendgrid&status=ACTIVE)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
bash
python <
data = json.dumps({app: sendgrid}).encode()
req = urllib.request.Request(https://ctrl.maton.ai/connections, data=data, method=POST)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Content-Type, application/json)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections/{connection_id})
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
响应:
json
{
connection: {
connection_id: 943c6cd5-9a56-4f5b-8adf-ecd4a140049f,
status: ACTIVE,
creation_time: 2026-02-11T10:53:41.817938Z,
lastupdatedtime: 2026-02-11T10:54:05.554084Z,
url: https://connect.maton.ai/?session_token=...,
app: sendgrid,
metadata: {}
}
}
在浏览器中打开返回的 url 以完成 OAuth 授权。
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections/{connection_id}, method=DELETE)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果您有多个 SendGrid 连接,请使用 Maton-Connection 头指定要使用的连接:
bash
python <
req = urllib.request.Request(https://gateway.maton.ai/sendgrid/v3/user/profile)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Maton-Connection, 943c6cd5-9a56-4f5b-8adf-ecd4a140049f)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果省略,网关将使用默认(最旧)的活动连接。
所有 SendGrid API 端点遵循以下模式:
/sendgrid/v3/{resource}
bash
POST /sendgrid/v3/mail/send
Content-Type: application/json
{
personalizations: [
{
to: [{email: recipient@example.com, name: Recipient}],
subject: Hello from SendGrid
}
],
from: {email: sender@example.com, name: Sender},
content: [
{
type: text/plain,
value: This is a test email.
}
]
}
带 HTML 内容:
bash
POST /sendgrid/v3/mail/send
Content-Type: application/json
{
personalizations: [
{
to: [{email: recipient@example.com}],
subject: HTML Email
}
],
from: {email: sender@example.com},
content: [
{
type: text/html,
value:
This is an HTML email.
带模板:
bash
POST /sendgrid/v3/mail/send
Content-Type: application/json
{
personalizations: [
{
to: [{email: recipient@example.com}],
dynamictemplatedata: {
first_name: John,
order_id: 12345
}
}
],
from: {email: sender@example.com},
template_id: d-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}
bash
GET /sendgrid/v3/user/profile
响应:
json
{
type: user,
userid: 59796657
}
bash
GET /sendgrid/v3/user/account
bash
GET /sendgrid/v3/marketing/contacts
响应:
json
{
result: [],
contact_count: 0,
_metadata: {
self: https://api.sendgrid.com/v3/marketing/contacts
}
}
bash
POST /sendgrid/v3/marketing/contacts/search
Content-Type: application/json
{
query: email LIKE %@example.com%
}
bash
PUT /sendgrid/v3/marketing/contacts
Content-Type: application/json
{
contacts: [
{
email: contact@example.com,
first_name: John,
last_name: Doe
}
]
}
响应:
json
{
job_id: 2387e363-4104-4225-8960-4a5758492351
}
注意: 联系人操作是异步的。使用任务状态端点检查进度。
bash
GET /sendgrid/v3/marketing/contacts/imports/{job_id}
响应:
json
{
id: 2387e363-4104-4225-8960-4a5758492351,
status: pending,
jobtype: upsertcontacts,
results: {
requested_count: 1,
created_count: 1
},
started_at: 2026-02-11T11:00:14Z
}
bash
DELETE /sendgrid/v3/marketing/contacts?ids=contactid1,contactid2
bash
GET /sendgrid/v3/marketing/contacts/{contact_id}
bash
POST /sendgrid/v3/marketing/contacts/search/emails
Content-Type: application/json
{
emails: [contact@example.com]
}
bash
GET /sendgrid/v3/marketing/lists
响应:
json
{
result: [],
_metadata: {
self: https://api
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 sendgrid-1776194297 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 sendgrid-1776194297 技能
skillhub install sendgrid-1776194297
文件大小: 6.16 KB | 发布时间: 2026-4-15 11:14