dsfsw1233 2019-05-29 07:38
浏览 68

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

I am trying to create a record in zohocrm. i am using API version2 code. i recieve this following error which i stated below. I tried stackoverflow for solutions but can't find relevant solution. I tried this Stackoverflow answer Zoho API V2 Update Record. It doesn't work for me. Help me with some solution. i use php version
7.1

Here's the Code i used:

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 Call Code:

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;
}

error i got:

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

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

        )

)
  • 写回答

1条回答 默认 最新

  • donglan6777 2019-05-31 08:37
    关注

    By the details which you gave ,

    (1)you said you wish to create "Contacts" , but the url you are using to create contact doesn't seems to create "Contacts" either by

    **converting leads to account and contact , or

    **directly creating contact

    (2)you mentioned module name as "Lead" , try changing it to "Leads".

    (3)variables $data_array & $extraParams , doesn't seems to hold any value , they seems to be null.

    (4)Here is a help doc. for you

    Create Contact



    If that still doesn't solve your problem ,you could ask your queries at zoho crm community , people will definitely solve your queries Ask here

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?