使用PHP中的REST API在SalesForce中创建潜在客户

前端之家收集整理的这篇文章主要介绍了使用PHP中的REST API在SalesForce中创建潜在客户前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在过去的几天里,我一直在尝试从SalesForce的REST API创建一个领导者,但是我不能为我的生活做好准备.我能够获得访问令牌没有问题,但从那里创建一个线索我完全没有运气.

我在所有文档中都看到了这个:

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Account/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d @newaccount.json"

我怎么能用PHP的卷曲呢?我尝试过但尝试过但根本没有运气.

以下是我获取访问令牌的方法

$ch = curl_init();

// set URL options

curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_URL,"https://login.salesforce.com/services/oauth2/token?grant_type=password&client_id=".CONSUMER_KEY."&client_secret=".CONSUMER_SECRET."&username=".USERNAME."&password=".USERPASS.SECURITY_TOKEN);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

// grab HTML
$data = curl_exec($ch);

$data = json_decode($data,true);
$code = $data['access_token'];

curl_close($ch);

在这段代码之后我尝试过这样的事情,但是我没有运气.

$token_url = LOGIN_BASE_URL.'/services/oauth2/token';

$post_fields = array(
    'code' => $code,'grant_type' => 'authorization_code','client_id' => CONSUMER_KEY,'client_secret' => CONSUMER_SECRET,);

$ch = curl_init();
curl_setopt($ch,$token_url);
curl_setopt($ch,TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,CURLOPT_POSTFIELDS,$post_fields);

$token_request_body = curl_exec($ch)

我只需要弄清楚如何在SalesForce中创建潜在客户,我不知道从哪里开始.任何帮助将不胜感激,因为我无法在任何有助于我的地方找到合适的文档.

创建帐户演示,应该让你开始:
function create_account($name,$instance_url,$access_token) {
    $url = "$instance_url/services/data/v20.0/sobjects/Account/";

    $content = json_encode(array("Name" => $name));

    $curl = curl_init($url);
    curl_setopt($curl,false);
    curl_setopt($curl,true);
    curl_setopt($curl,CURLOPT_HTTPHEADER,array("Authorization: OAuth $access_token","Content-type: application/json"));
    curl_setopt($curl,$content);

    $json_response = curl_exec($curl);

    $status = curl_getinfo($curl,CURLINFO_HTTP_CODE);

    if ( $status != 201 ) {
        die("Error: call to URL $url Failed with status $status,response $json_response,curl_error " . curl_error($curl) . ",curl_errno " . curl_errno($curl));
    }

    echo "HTTP status $status creating account<br/><br/>";

    curl_close($curl);

    $response = json_decode($json_response,true);

    $id = $response["id"];

    echo "New record id $id<br/><br/>";

    return $id;
}
原文链接:https://www.f2er.com/php/134697.html

猜你在找的PHP相关文章