HubSpot API创建deal时传入填充数据不生效,仅生成空白交易单问题
问题原因
HubSpot CRM v3 创建Deal接口要求所有业务字段必须嵌套在properties属性下,你当前代码直接将字段放在请求体根层级,接口无法识别对应字段,因此仅生成空白Deal。
修复后的代码
import json import requests hubspot_api_key = "MY_API_KEY" url = 'https://api.hubapi.com/crm/v3/objects/deals?hapikey={}'.format(hubspot_api_key) headers = {"Content-Type": "application/json"} deals_post = { # 所有字段放入properties节点下 "properties": { 'amount': "4034.75", 'closedate': '2021-05-10T12:04:00.000Z', 'dealname': 'Custom data integrations', 'dealstage': 'closedwon', 'hubspot_owner_id': "5448459615", 'pipeline': 'default' } } response = requests.post(url, headers=headers, data=json.dumps(deals_post)) print(response.text)
你也可以直接使用requests自带的json参数简化代码,无需手动做JSON序列化:response = requests.post(url, headers=headers, json=deals_post)
修改后重新调用即可正常写入所有字段值。
内容的提问来源于stack exchange,提问作者Yuriy Glukhov
相关产品推荐
相关产品推荐

