首页 > 解决方案 > Hubspot API 未填充交易

问题描述

当我尝试通过 hubspot api 创建交易时,即使我正在通过填充的数据,所创建的只是一个完全空白的交易

API 网址:https ://developers.hubspot.com/docs/api/crm/deals

这是我正在尝试的以下代码:

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 = {
    '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)

这是它的结果:

在此处输入图像描述

标签: pythonapipython-requestscrmhubspot

解决方案


此问题的解决方案是将属性添加到数据字典

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': {
        'amount': "4034.75",
        'closedate': '2021-05-10T12:04:00.000Z',
        'dealname': 'Custom data integrations',
        'dealstage': 'closedwon',
        'hubspot_owner_id': 83849850,
        'pipeline': 'default'
    }
}

response = requests.post(url, headers=headers, data=json.dumps(deals_post))
print(response.text)

这会根据传入的数据生成一个已填写的交易


推荐阅读