如何使用Zoho CRM v2 API添加Zoho CRM潜在客户 [英] How To Add Zoho CRM Leads with the Zoho CRM v2 API

查看:131
本文介绍了如何使用Zoho CRM v2 API添加Zoho CRM潜在客户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用简单的卷曲连接通过Zoho CRM v2 API添加Zoho CRM Lead?这些文档不仅在如何添加线索方面还不清楚,在如何获得适当的oAuth令牌来创建线索方面也不是很清楚.

How do I add a Zoho CRM Lead with the Zoho CRM v2 API, using simple curl connections? The docs are not very clear on not only how to add a lead, but how to even get the proper oAuth token to create the lead.

推荐答案

The docs are not very clear on this process. So, I'll simplify this. The biggest hurdle are the steps to get the refresh token. Once you have that, you can generate countless access tokens that are used to make the actual API calls.

  1. 使用管理员帐户登录到您的Zoho CRM ,并在标签中打开该帐户.然后,在另一个浏览器选项卡中,登录到开发人员API控制台: https://api-console.zoho.com/
  2. 在开发人员API控制台中,您需要创建一个服务器端客户端.字段的填充方式应为:客户端名称(您想要的任何逻辑名称),首页URL (您将在其中制作API的域的首页)调用,或仅使用相同的URL进行重定向),授权的重定向URI (将网页放置在您要进行API调用的域上只发出"zoho确认"). ("zoho确认"不是必需的,也未在文档中提及,但确实可以帮助您更好地理解该过程.)单击创建".
  3. 创建后,再次单击它,然后有一个名为客户端机密"的选项卡.单击它,然后在记事本中记录您的 Client ID Client Secret .
  4. 在线获取URL编码器脚本(或使用PHP或任何其他工具),并对下一步要组成并加载到浏览器中的新URL的URL进行以下参数编码:
  1. Login to your Zoho CRM with an admin-level account and have that open in a tab. Then, in another browser tab, login into the Developer API Console: https://api-console.zoho.com/
  2. In the Developer API Console, you need to create a Server-Side Client. The fields should be populated like so: Client Name (any logical name you want), Homepage URL (the homepage of the domain where you're going to be making the API calls, or just use the same URL for where you're doing the redirects), Authorized Redirect URIs (put a web page up on the domain where you're going to make the API call and make it emit nothing more than "zoho confirmed"). (The "zoho confirmed" is not required and not mentioned in the docs, but does help you understand the process better.) Click Create.
  3. Once created, click on it again and there's a tab called Client Secret. Click it and record in a notepad your Client ID and Client Secret.
  4. Take a URL encoder script online (or use PHP or any other tool) and URL encode the following parameters for a new URL you need to compose and load in your browser in the next step:

scope: ZohoCRM.modules.ALL,ZohoCRM.settings.ALL,ZohoCRM.users.ALL,ZohoCRM.org.ALL,aaaserver.profile.ALL,ZohoCRM.settings.functions.all,ZohoCRM.notifications.all,ZohoCRM.coql.read,ZohoCRM.files.create,ZohoCRM.bulk.all
response_type: code
access_type: offline
client_id: {use the Client ID you recorded in step 3}
redirect_uri: {use the Authorized Redirect URI you generated in step 2}

  1. 使用这些URL编码的参数,将它们传递到浏览器中该URL的末尾:https://accounts.zoho.com/oauth/v2/auth?这样,您将具有类似于以下内容的信息:
  1. With those URL encoded parameters, pass them to the end of this URL in your browser: https://accounts.zoho.com/oauth/v2/auth? Thus, you would have something similar to:

https://accounts.zoho.com/oauth/v2/auth?scope=ZohoCRM.modules.ALL%2CZohoCRM.settings.ALL%2CZohoCRM.users.ALL%2CZohoCRM.org.ALL%2Caaaserver.profile.ALL%2CZohoCRM.settings.functions.all%2CZohoCRM.notifications.all%2CZohoCRM.coql.read%2CZohoCRM.files.create%2CZohoCRM.bulk.all&client_id=1000.TTT0BSTTTC9TTTRILR3MGXBYAC82LH&response_type=code&access_type=offline&redirect_uri=https%3A%2F%2Fexample.com%3Azohoconfirm

请注意,如果您的重定向URI(例如 https://example.com/zohoconfirm (如上),使用301或302重定向进行另一种重定向,并且也不会转发这些查询参数,那么您将丢失在完成后需要查看的参数.

Please note that if your redirect URI (like https://example.com/zohoconfirm, above) does another redirection with like a 301 or 302 redirect and doesn't also forward those query parameters, then you'll lose the parameters you need to see when finished.

  1. 将其加载到浏览器中后,您将看到一个接受"按钮.如果不这样做,那么您可能已经错过了在第1步中应该在一个选项卡中登录CRM的信息,然后打开一个新选项卡来执行其他任务.这样可以为您打开一个会话,并且知道执行第5步时您是谁.

  1. Once you load that in your browser, you will see an Accept button. If you do not, then you may have missed that in step 1 you were supposed to login to the CRM in one tab, and then open a new tab to do other tasks. That makes a session open for you and it knows who you are when doing step 5.

单击接受"按钮后,Zoho的帐户系统会将您重定向到您指定的授权重定向URI.因此,如果您完全按照这些步骤操作,您应该会看到一些输出,例如"zoho Confirmed".但是不要关闭选项卡.查看选项卡的URL,然后将其剪切/粘贴到记事本中.在其中,获取该 code 参数.

After you click the Accept button, Zoho's account system will redirect you to your Authorized Redirect URI that you specified. So, if you followed these steps exactly, you should see some output like "zoho confirmed". But do not close the tab. Look at the URL of the tab and cut/paste it into your notepad. In there, grab that code parameter.

现在有了该代码参数,您需要创建一个特殊的Curl POST请求.您可以通过命令行或使用自己喜欢的编程语言来执行此操作.在Linux上的命令行中,它看起来类似于以下内容:

Now that you have that code parameter, you need to create a special Curl POST request. You can do this either via command line or with your favorite programming language. From command line on Linux, this would look something like the following:

curl "https://accounts.zoho.com/oauth/v2/token" \
-X POST \
-d "grant_type=authorization_code&code=1000.aaa1f9aa8582eaaaafeaddfaf0f3b6b.bf7fe646ba899783501c21a9a3240aaa&client_id=1000.AAAA0BSIC7C9AAAARILR3MGXBYAC8AAA&client_secret=aaa9aa9166055932ff8c0279c6253a65cb534daaaa&redirect_uri=https%3A%2F%2Fexample.com%2Fzohoconfirm"

您需要填写的URL编码参数是:

The URL-encoded parameters you need to fill out are:

grant_type: authorization_code
code: {the code you recorded from step 7}
client_id: {the Client ID you recorded in step 3}
client_secret: {the Client Secret you recorded in step 3}
redirect_uri: {the Authorized Redirect URI you recorded in step 2}

  1. 运行该Curl命令后,它将返回一些类似于以下内容的JSON:

{"access_token":"1000.aaaa5579abeea73871b096c941ec1df8.7835dbb43bbf5122f2d5810f0b65aaa","refresh_token":"1000.aaaa2683a1723d1aeb7b58899849aaaa.aaaa4c22481da67e85e598f4b988aaa","api_domain":"https://www.zohoapis.com","token_type":"Bearer","expires_in":3600}

  1. 现在,在JSON输出中,您可以使用该 access_token 进行API调用以生成销售线索,但最好还是采用该 refresh_token ,并将其放入配置文件中,以便以后在编程中使用.根据他们的文档,他们的refresh_token会永远持续下去.您应该将其保存在一个非常安全的地方.
  1. Now, in the JSON output, you could use that access_token to make an API call to generate the lead, but you're better off just taking that refresh_token and putting that in a configuration file for later use in your programming. According to their documentation, their refresh_token lasts forever. You should keep this in an extremely secure place.

如何获取访问令牌

  1. 现在,您获得了 refresh_token ,可以在每次需要进行API调用时使用它来生成新的 access_token .为此,请使用与下面类似的URL进行另一个Curl POST.以带有Curl的Linux命令行为例,如下所示:
  1. Now that you get your refresh_token, you use it to generate a fresh access_token each time you need to make an API call. To do that, make another Curl POST with a URL similar to below. In Linux command line with Curl, as an example, here's what it would look like:

curl "https://accounts.zoho.com/oauth/v2/token" \
-X POST \
-d "grant_type=refresh_token&refresh_token=1000.aaaa2683a1723d1aeb7b58899849aaaa.aaaa4c22481da67e85e598f4b988aaa&client_id=1000.AAAA0BSIC7C9AAAARILR3MGXBYAC8AAA&client_secret=aaa9aa9166055932ff8c0279c6253a65cb534daaaa"

以下是有关如何进行URL编码的参数的说明:

Here's an explanation of how to do the URL-encoded parameters:

grant_type: refresh_token
refresh_token: {use the refresh_token (the one I said that would last forever) from your stored config file from step 10 in the previous steps}
client_id: {use your client_id}
client_secret: {use your client_secret} 

  1. 运行上述命令应返回给您一些类似于以下内容的JSON:

{"access_token":"1000.aaa1c95788b34226c2844a841bfd1d5.6aff70f4adbc3fee9e6b57579e481aaa","api_domain":"https://www.zohoapis.com","token_type":"Bearer","expires_in":3600}

  1. 使用您喜欢的编程语言,将收到的 access_token 存储在一个临时变量中,以便您可以进行API调用来执行类似添加Zoho CRM Lead之类的操作.该访问令牌将持续3600秒(1小时),但实际上没有关系,因为您可以将无限刷新令牌存储在配置文件中,因此您可以生成无限个访问令牌.
  1. In your favorite programming language, you'll be storing that access_token you received in a temporary variable so that you can make an API call to do something like add a Zoho CRM Lead. That access token will last 3600 seconds (1 hour), but really is of no consequence because you can generate infinite access tokens since you have that refresh_token stored in a configuration file.

如何创建Zoho CRM主管

  1. 在您最喜欢的编程语言中,您将使用该刷新令牌创建访问令牌,然后将其用于以下标头以传递您的API调用:

Authorization: Zoho-oauthtoken XXXXXX

......其中XXXXXX是您从上一组说明中获得的access_token.

...where XXXXXX is the access_token you received from the previous set of instructions.

  1. 这是PHP中带有file_get_contents的示例(尽管您可以对PHP的Curl进行相同操作)来请求添加Zoho CRM Lead.您可以采用以下示例,然后以您喜欢的编程语言对其进行重新编码.将$ sAccessToken值更改为您生成的值.

注意,下面,我们还将写到一个名为"Lead Source"的字段中,它可通过API访问的名称是"Lead_Source". (如果您最终更改了下面的代码以写入联系人"或客户",那么我想创建一个自定义字段来指明联系人或客户的来源.例如,如果您购物购物车,那么您可以指示记录来自完成该交易,而不是来自客户的来电.)

Note, below, we're also writing into a field called "Lead Source", and it's API-accessible name is "Lead_Source". (If you end up changing the code below to write into Contacts or Accounts, then you'll want to create a custom field, I'm sure, to indicate where the contact or account came from. For instance, if you have a shopping cart, then you could indicate the record came from completing that transaction, rather than a customer calling in.)

<?php

error_reporting(E_ALL);
ini_set('display_errors','On');
header('Content-Type: text/plain');

$sAccessToken = '1000.aaaa5579abeea73871b096c941ec1df8.7835daaa3bbf5122f2d5810f0b65aaaa'; // change me
$sJSON = json_encode(array(
    'First_Name' => 'Mickey',
    'Last_Name' => 'Mouse',
    'Email' => 'mickey@example.com',
    'Phone' => '444-444-4444',
    'Lead_Source' => 'TEST1'
  ));
  $sJSON = str_replace('{','[{',$sJSON);
  $sJSON = str_replace('}','}]',$sJSON);
  $sJSON = '{"data":' . $sJSON . '}';
echo "SENDING: $sJSON\n";
$sURL = 'https://www.zohoapis.com/crm/v2/Leads';
$sResponse = @ file_get_contents($sURL,false,stream_context_create(array('http'=>array(
  'ignore_errors' => TRUE, // critical if you want to see errors in response instead of empty on error
  'method' => 'POST',
  'header' => array(
    'Content-Type: application/json',
    "Authorization: Zoho-oauthtoken $sAccessToken",
    'cache-control: no-cache'
  ),
  'content' => $sJSON
))));
echo "$sResponse\n";

如果成功,将产生类似于以下的响应:

If successful, this will generate a response similar to below:

{"data":[{"code":"SUCCESS","details":{"Modified_Time":"2020-05-21T20:45:24-04:00","Modified_By":{"name":"John Manager","id":"9999889000000279991"},"Created_Time":"2020-05-21T20:45:24-04:00","id":"9999889000000279991","Created_By":{"name":"John Manager","id":"9999889000000279991"}},"message":"record added","status":"success"}]}

......,其中John Manager将是您用来登录CRM的管理员级别用户帐户的名称.

...where John Manager would be the name of the admin-level user account you logged into the CRM with.

有关Zoho CRM插入记录API的更多信息,可以在这里找到:

More information about the Zoho CRM Insert Record API can be found here: https://www.zoho.com/crm/developer/docs/api/insert-records.html

要了解在API中可找到API可寻址字段名称的位置,请转到:设置>开发人员空间> API> API名称>潜在客户.从过滤依据"下拉列表中选择字段".

To understand where to find the API-addressable field names, in your CRM, go to: Setup > Developer Space > APIs > API Names > Leads. Choose "Fields" from the "Filter By" drop-down.

请注意,此API不会查找重复项.您可以修改上面的内容以执行"upsert"而不是"insert":

Note that this API does not look for duplicates. You can adapt the above to do an "upsert" instead of an "insert": https://www.zoho.com/crm/developer/docs/api/upsert-records.html

如果您将联系人"和客户"编辑为具有与潜在客户"相同的自定义字段,则可以将https://www.zohoapis.com/crm/v2/Leads行更改为https://www.zohoapis.com/crm/v2/Contactshttps://www.zohoapis.com/crm/v2/Accounts,并将条目也写入其中.

If you edit the Contacts and Accounts to have the same custom fields as Leads, then you can change the https://www.zohoapis.com/crm/v2/Leads line to https://www.zohoapis.com/crm/v2/Contacts or https://www.zohoapis.com/crm/v2/Accounts and write entries into those as well.

这篇关于如何使用Zoho CRM v2 API添加Zoho CRM潜在客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆