[英]How To Add Zoho CRM Leads with the Zoho CRM v2 API
如何使用簡單的 curl 連接,使用 Zoho CRM v2 API 添加 Zoho CRM 潛在客戶? 文檔不僅關於如何添加潛在客戶,甚至如何獲得正確的 oAuth 令牌來創建潛在客戶都不是很清楚。
文檔對此過程不是很清楚。 所以,我會簡化一下。 最大的障礙是獲取刷新令牌的步驟。 一旦你有了它,你就可以生成無數的訪問令牌,用於進行實際的 API 調用。
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}
https://accounts.zoho.com/oauth/v2/auth?
因此,你會有類似的東西: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 重定向進行另一個重定向,並且不轉發這些查詢參數,那么您將丟失所需的參數看看什么時候完成。
在瀏覽器中加載它后,您將看到一個接受按鈕。 如果您不這樣做,那么您可能錯過了在第 1 步中您應該在一個選項卡中登錄 CRM,然后打開一個新選項卡來執行其他任務。 這使得 session 為您打開,並且在執行第 5 步時它知道您是誰。
單擊接受按鈕后,Zoho 的賬戶系統會將您重定向到您指定的授權重定向 URI。 因此,如果您完全按照這些步驟操作,您應該會看到一些 output,例如“zoho 確認”。 但不要關閉選項卡。 查看選項卡的 URL 並將其剪切/粘貼到記事本中。 在那里,抓住那個代碼參數。
現在您有了該代碼參數,您需要創建一個特殊的 Curl POST 請求。 您可以通過命令行或使用您喜歡的編程語言來執行此操作。 從 Linux 上的命令行,這將類似於以下內容:
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 編碼參數有:
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}
{"access_token":"1000.aaaa5579abeea73871b096c941ec1df8.7835dbb43bbf5122f2d5810f0b65aaa","refresh_token":"1000.aaaa2683a1723d1aeb7b58899849aaaa.aaaa4c22481da67e85e598f4b988aaa","api_domain":"https://www.zohoapis.com","token_type":"Bearer","expires_in":3600}
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 編碼參數的說明:
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}
{"access_token":"1000.aaa1c95788b34226c2844a841bfd1d5.6aff70f4adbc3fee9e6b57579e481aaa","api_domain":"https://www.zohoapis.com","token_type":"Bearer","expires_in":3600}
Authorization: Zoho-oauthtoken XXXXXX
...其中 XXXXXX 是您從上一組指令中收到的 access_token。
請注意,下面,我們還將寫入一個名為“Lead Source”的字段,它的 API 可訪問名稱是“Lead_Source”。 (如果您最終更改下面的代碼以寫入聯系人或帳戶,那么您肯定需要創建一個自定義字段來指示聯系人或帳戶的來源。例如,如果您有購物購物車,那么您可以表明記錄來自完成該交易,而不是客戶來電。)
<?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";
如果成功,這將生成類似於以下的響應:
{"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 時使用的管理員級用戶帳戶的名稱。
有關 Zoho CRM 插入記錄 API 的更多信息,可在此處找到:https://www.zoho.com/crm/developer/docs/api/insert-records.ZFC35FDC70D5FC69A5D269883A822C7
要了解在哪里可以找到 API 可尋址字段名稱,在您的 CRM 中,go 到:設置 > 開發人員空間 > API > API 名稱 > 潛在客戶。 從“篩選依據”下拉列表中選擇“字段”。
請注意,此 API 不會查找重復項。 您可以調整上述內容以執行“upsert”而不是“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/Contacts
或https://www.zohoapis.com/crm/v2/Accounts
並將條目也寫入其中。
步驟: 1. 使用自己的客戶端創建授權碼。 2. 使用此授權碼,您可以創建訪問和刷新令牌。 3. 使用此刷新令牌,您可以創建一個新的訪問令牌4. 將這個新創建的新訪問令牌用於 API。
map 中的參數傳遞用於 header 和主體。
如果您知道 POSTMAN,那么 Postman 集合可用於 CRM。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.