如何处理 zoho api searchRecords 中的特殊字符(例如:'and'、'-' 等)?

How to handle special character (e.g : '&', '-' etc) in zoho api searchRecords?

我在 Zoho CRM 工作。当我必须搜索记录时,我无法理解如何处理特殊字符。

这是我正在尝试的代码。

<?php

    $product_name  = "99X210MM DL - SINGLE SUPPLY & ATTACHMENT"; // not working with this
    $product_name1 = "99X210MM DL SINGLE SUPPLY TTACHMENT"; // working with this

    $auth   = "------------------------"; //can't share 
    $url    ="https://crm.zoho.com/crm/private/json/Products/searchRecords";
    $query  ="authtoken=".$auth."&scope=crmapi&criteria=(Product Name:".$product_name.")"; 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
    $response = curl_exec($ch);
    curl_close($ch);
    $rslt = json_decode($response); 
    echo "<pre>"; print_r($rslt);

?>

结果:

stdClass Object
(
    [response] => stdClass Object
        (
            [uri] => /crm/private/json/Products/searchRecords
            [error] => stdClass Object
                (
                    [code] => 4832
                    [message] => API call cannot be completed as the Criteria parameter value is invalid
                )

        )

)

考虑使用 urlencode 对您的特殊字符进行编码。

urlencode($product_name)