如何在PHP的前提下使用动态CRM来创建潜在客户

时间:2016-11-24 04:33:03

标签: php rest api curl soap

我想在php中使用api在动态CRM中创建潜在客户。目前我正在使用rest api,使用curl但它正在抛出错误 -

  

HTTP错误401 - 未经授权:访问被拒绝状态:401NULL   string(371)“HTTP / 1.1 401 Unauthorized Cache-Control:private   转移编码:分块...

请有人帮帮我。

这是我的代码:

    $ZDURL= "https://[org]/api/data/v8.1/accounts";

    $data =curlWrap($ZDURL); 
    var_dump($data);

    function curlWrap($ZDURL)
    {    
        $ch = curl_init();  
        curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
    curl_setopt($ch, CURLOPT_URL, $ZDURL);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

    $result = curl_exec($ch);
    if( $result === false) 
    {echo 'Curl error: ' . curl_error($ch); }
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    $output = curl_exec($ch);

    $status = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
    echo "Status: ".$status;
    curl_close($ch);
    $decoded = json_decode($output);
    return $decoded;
}

0 个答案:

没有答案