Zoho CRM API:Python基于请求的POST或GET身份验证+联系人插入

2024-04-20 11:50:43 发布

您现在位置:Python中文网/ 问答频道 /正文

任务##

django应用程序允许用户注册,一旦用户单击帐户激活链接,Zoho CRM将接收数据,并在CRM部分创建联系人

问题

我目前正在创作一部绝对的杰作——ZohoAPI。 我正在努力设置使用POST/GET请求的本机Python代码。 关于zcrmsdk 3.0.0,我已经完全放弃了这个解决方案,除非有人能够提供一个完整的功能示例。支持人员只是责怪我的代码

我查阅的文件: https://www.zoho.com/crm/developer/docs/api/v2/access-refresh.htmlhttps://www.zoho.com/crm/developer/docs/api/v2/insert-records.html

由于PostManAPI中的post请求工作正常,我不理解为什么它在python代码中不工作

我的方法

  1. 在:https://api-console.zoho.com/上生成自客户端API代码
  2. 在邮递员上插入该代码并检索访问或刷新令牌
  3. 在文档中定义的添加用户联系人功能中使用此访问令牌 它起作用了!在Zoho CRM中,响应就是成功

我使用的权限范围是:ZohoCRM.modules.contacts.ALL、ZohoCRM.users.ALL、ZohoCRM.modules.deals.ALL、ZohoCRM.modules.attachments.ALL、ZohoCRM.settings.ALL、AAAserver.profile.ALL

邮递员邮递申请图片

the header

the body content

the expected response

我自己的代码

def authenticate_crm():

"""
access to response object id:
response_object.get('data')[0].get('details').get('id')
"""

url = 'https://accounts.zoho.com/oauth/v2/token'

headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
}

# one time self-client token here -
request_body = {
    "code": "1000.aa8abec144835ab79b8f9141fa1fb170.8ab194e4e668b8452847c7080c2dd479",
    "redirect_uri": "http://example.com/yourcallback",
    "client_id": "1000.H95VDM1H9KCXIADGF05E0E1XSVZKFQ",
    "client_secret": "290e505ec52685fa62a640d874e6560f2fc8632e97",
   " grant_type": "authorization_code"
}

response = requests.post(url=url, headers=headers, data=json.dumps(request_body).encode('utf-8'))
if response is not None:
    print("HTTP Status Code : " + str(response.status_code))
    print(response.json())

实际上,我正在努力将Postman API请求转换为Python请求,以作为工作流的一部分获取令牌。我做错了什么

文档说明:注意:出于安全原因,请将以下参数作为表单数据传递到请求正文中。(访问刷新链接),但将其作为表单数据传递给postman会完全中断调用

根据他们自己的文档(复杂、矛盾且充满过时的截图),认证密钥只需要一次。 一旦上面的请求运行,我将在第三个图像中获取响应,并使用刷新键添加联系人。 如果有人能提供帮助,我也愿意使用SDK 3.0.0解决方案


Tags: 代码文档httpscommodulesapiresponsewww
1条回答
网友
1楼 · 发布于 2024-04-20 11:50:43

我解决了

我改变了这一行:

response = requests.post(url=url, headers=headers, data=json.dumps(request_body).encode('utf-8'))

在此基础上,添加了一些返回语句:

payload =     '1000.6d9411488dcac999f02304d1f7843ab2.e14190ee4bae175debf00d2f87143b19&'     \
          'redirect_uri=http%3A%2F%2Fexample.com%2Fyourcallback&' \
          'client_id=1000.H95VDM1H9KCXIADGF05E0E1XSVZKFQ&' \
         'client_secret=290e505ec52685fa62a640d874e6560f2fc8632e97&'\
          'grant_type=authorization_code'

response = requests.request(method="POST", url=url, headers=headers,     data=payload)
if response is not None:
    print("HTTP Status Code : " + str(response.status_code))
    # print(response.text)
    print(response.json())
    # catch access and refresh token
at = response.json().get('access_token')
rt = response.json().get('refresh_token')

return at, rt

我不明白为什么这是不同的,但它修复了它,我可以从ZOHO检索钥匙

相关问题 更多 >