使用php 7.1在zohocrm联系人中创建记录时出错

时间:2019-05-29 07:38:00

标签: php json zoho

我正在尝试在zohocrm中创建一个记录。我正在使用API​​ version2代码。 我收到以下我指出的以下错误。我尝试了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
                )

        )

)

1 个答案:

答案 0 :(得分:0)

通过您提供的详细信息,

(1)您曾说过要创建“联系人”,但是您用来创建联系人的网址似乎也没有创建“联系人”

**将潜在客户转化为客户和联系人,或者

**直接创建联系人

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

(3)变量$ data_array和$ extraParams似乎没有任何值,它们似乎为空。

(4)这里是帮助文档。为你

Create Contact



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