Nic*_*way 15 sendgrid sendgrid-api-v3
我正在尝试更新我的 SendGrid 联系人,但无法弄清楚为什么我尝试更新联系人的自定义字段不起作用。我的保留字段(名字、姓氏、电子邮件)会更新,但我的自定义字段不会更新。有什么想法吗?
此处的文档:https ://sendgrid.api-docs.io/v3.0/contacts/add-or-update-a-contact
try:
headers = {
'authorization': f"Bearer {settings.SENDGRID_API_KEY}",
}
data = {
"list_ids": [
# "Users" list
"7c2...d20"
],
"contacts": [{
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name,
"custom_fields": {
"educator_role": user.educator_role,
}
}]
}
response = requests.put("https://api.sendgrid.com/v3/marketing/contacts", headers=headers, data=json.dumps(data))
if(response.status_code != 202):
capture_message(f"Could not add user with email {user.email} to Sendgrid.", level="error")
except:
capture_message(f"Adding/updating SendGrid contact failed for {user.email}.", level="error")```
Run Code Online (Sandbox Code Playgroud)
Mat*_*att 27
与保留字段不同,更新自定义字段需要您传递自定义字段而不是调用中的id字段。name因此educator_role,不要使用 id,而是使用 id,它将是类似 的随机值e1_T。
您可以通过/marketing/field_definitions端点获取 ID 。
| 归档时间: |
|
| 查看次数: |
4272 次 |
| 最近记录: |