【问题标题】:Error in creating record in zohocrm contacts using php 7.1使用 php 7.1 在 zohocrm 联系人中创建记录时出错
【发布时间】:2019-05-29 07:38:00
【问题描述】:

我正在尝试在 zohocrm 中创建记录。我正在使用 API 版本 2 代码。 我收到以下错误,我在下面说明。我尝试了 stackoverflow 的解决方案,但找不到相关的解决方案。我试过这个 Stackoverflow 答案Zoho API V2 Update Record。它对我不起作用。帮我解决一些问题。我使用 php 版本
7.1

这是我使用的代码:

public function createRecord($module, $module_fields)
{
    global $HelperObj;
    $WPCapture_includes_helper_Obj = new WPCapture_includes_helper_PRO();
    $activateplugin = $WPCapture_includes_helper_Obj->ActivatedPlugin;
    $moduleslug = $this->ModuleSlug = rtrim(strtolower($module), "s");
    $zohoapi = new SmackZohoApi();
    $module_field['data'] = array($module_fields);
    $module_field['Owner']['id'] = $module_fields['SMOWNERID'];

    $fields_to_skip = ['Digital_Interaction_s', 'Solution'];
    foreach ($module_fields as $fieldname => $fieldvalue) {
        if (!in_array($fieldname, $fields_to_skip)) {
            continue;
        }

        $module_fields[$fieldname] = array();

        if (is_string($fieldvalue)) {
            array_push($module_fields[$fieldname], $fieldvalue);
        } else if (is_array($fieldvalue)) {
            array_push($module_fields[$fieldname], $fieldvalue);
        }
    }

    //$fields = json_encode($module_fields);

    $attachments = $module_fields['attachments'];
    $body_json = array();
    $body_json["data"] = array();
    array_push($body_json["data"], $module_fields);

    $record = $zohoapi->Zoho_CreateRecord($module, $body_json, $attachments);
    if ($record['code'] == 'INVALID_TOKEN' || $record['code'] == 'AUTHENTICATION_FAILURE') {
        $get_access_token = $zohoapi->refresh_token();
        if (isset($get_access_token['error'])) {
            if ($get_access_token['error'] == 'access_denied') {
                $data['result'] = "failure";
                $data['failure'] = 1;
                $data['reason'] = "Access Denied to get the refresh token";
                return $data;
            }
        }

        $exist_config = get_option("wp_wpzohopro_settings");
        $config['access_token'] = $get_access_token['access_token'];
        $config['api_domain'] = $get_access_token['api_domain'];
        $config['key'] = $exist_config['key'];
        $config['secret'] = $exist_config['secret'];
        $config['callback'] = $exist_config['callback'];
        $config['refresh_token'] = $exist_config['refresh_token'];
        update_option("wp_wpzohopro_settings", $config);
        $this->createRecord($module, $module_fields);
    } elseif ($record['data'][0]['code'] == 'SUCCESS') {
        $data['result'] = "success";
        $data['failure'] = 0;
    } else {
        $data['result'] = "failure";
        $data['failure'] = 1;
        $data['reason'] = "failed adding entry";
    }
    return $data;
}

API 调用代码:

public function Zoho_CreateRecord($module = "Lead",$data_array,$extraParams) {
    try{
        $apiUrl = "https://www.zohoapis.com/crm/v2/$module";
        $fields = json_encode($data_array);
        $headers = array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($fields),
            sprintf('Authorization: Zoho-oauthtoken %s', $this->access_token),
        );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $apiUrl);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        $result = curl_exec($ch);

        curl_close($ch);
        $result_array = json_decode($result,true);
        if($extraParams != "")
        {
            foreach($extraParams as $field => $path){
                $this->insertattachment($result_array,$path,$module);
            }
        }
    }catch(\Exception $exception){
        // TODO - handle the error in log
    }
    return $result_array;
}

我得到的错误:

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [code] => INVALID_DATA
                    [details] => Array
                        (
                            [expected_data_type] => jsonarray
                            [api_name] => Solution_Interest
                        )

                    [message] => invalid data
                    [status] => error
                )

        )

)

【问题讨论】:

    标签: php json zoho


    【解决方案1】:

    根据您提供的详细信息,

    (1)您说您希望创建“联系人”,但您用于创建联系人的 url 似乎也没有通过

    创建“联系人”

    **将潜在客户转换为帐户和联系人,或

    **直接创建联系人

    (2)您提到模块名称为“Lead”,请尝试将其更改为“Leads”。

    (3)变量 $data_array & $extraParams ,似乎没有任何价值,它们似乎是空的。

    (4)这是一个帮助文档。给你

    Create Contact



    如果仍然不能解决您的问题,您可以在 zoho crm 社区提出您的问题,人们一定会解决您的问题Ask here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-25
      • 2013-06-10
      • 1970-01-01
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多