【发布时间】:2021-02-25 23:51:08
【问题描述】:
我正在尝试更新我的 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")```
【问题讨论】:
-
令人吃惊的是,文档中根本没有提到这一点。在同一主题上找到这个 github 线程,交叉链接...github.com/sendgrid/sendgrid-nodejs/issues/953