【发布时间】:2019-06-15 04:41:06
【问题描述】:
我正在尝试将 Freshsales 功能集成到我的 Django 服务器中,以便创建潜在客户、安排约会等。但是,Freshsale 的 Python API 文档缺乏详细信息。以下是使用 curl 命令的 API 功能链接:https://www.freshsales.io/api/。
他们的python代码如下:
from .freshsales_exception import FreshsalesException
import requests
import json
def _request(path, payload):
try:
data = json.dumps(payload)
headers = { 'content-type': 'application/json', 'accept': 'application/json' }
resp = requests.post(path, data=data, headers=headers)
if resp.status_code != 200:
raise FreshsalesException("Freshsales responded with the status code of %s" % str(resp.status_code))
except requests.exceptions.RequestException as e:
raise FreshsalesException(e.message)
以curl命令为例,创建约会,是:
curl -H "Authorization: Token token=sfg999666t673t7t82" -H "Content-Type: application/json" -d '{"appointment":{"title":"Sample Appointment","description":"This is just a sample Appointment.","from_date":"Mon Jun 20 2016 10:30:00 GMT+0530 (IST)","end_date":"Mon Jun 20 2016 11:30:00 GMT+0530 (IST)","time_zone":"Chennai","location":"Chennai, TN, India","targetable_id":"115765","targetable_type":"Lead", "appointment_attendees_attributes":[{ "attendee_type":"FdMultitenant::User","attendee_id":"223"},{"attendee_type":"FdMultitenant::User","attendee_id":"222"},{"attendee_type":"Lead","attendee_id":"115773"}] }}' -X POST
我了解我需要使用requests 库来发出发布请求。但是,我不明白我需要如何格式化请求。例如,我理解列出所有约会的最远范围是我的请求如下:
my_request = "https://mydomain.freshsales.io/api/appointments/token=myexampletoken"
response = requests.post(myrequest)
我不确定如何创建 API 接受的有效负载来创建约会。我如何使用requests 库来完成此任务?我搜索了如何在 Python 中执行 curl 命令,我看到的唯一答案是使用 requests 库。非常感谢任何帮助!
【问题讨论】:
标签: django python-3.x api python-requests