2014-11-24 136 views
2

我正在面臨在php中使用Base crm REST API的問題。如何使用cURL在PHP中調用Base crm REST API?

基本CRM爲REST API here這是

curl -X POST -H "X-Pipejump-Auth:auth-token" \ 
-H "Accept:application/xml" \ 
-H "Content-Type:application/json" \ 
--data "{\"contact\" : { \"last_name\" : \"Barowsky\", \ 
    \"first_name\" : \"Foo\", \"is_organisation\" : \"false\" }}" \ 
    https://sales.futuresimple.com/api/v1/contacts/ 

現在,任何人可以幫我如何使用cURL在PHP中使用此提供一些代碼。

我已經達到了高達這樣的:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/xml', 
    'Accept: application/xml', 
    'Connection: Keep-Alive')); 

curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect: ")); 

回答

2

UPDATE:基地已發佈API V2(https://developers.getbase.com/),與PHP庫一起:https://github.com/basecrm/basecrm-php。我建議使用它而不是下面的代碼片段。

這已經有一段時間了,但讓我們試試吧。

我推薦使用json而不是xml,這兩者都是用於請求和響應。

<?php 

$token = "your_api_token"; 

$headers = array(
    "X-Pipejump-Auth: " . $token, 
    "Content-Type: application/json", 
    "Accept: application/json", 
); 

$curl = curl_init(); 
$url = "https://sales.futuresimple.com/api/v1/contacts.json"; 

$data = array(
    "contact" => array("first_name" => "My", "last_name" => "Contact") 
); 
$data_string = json_encode($data); 

curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); 

$resp = curl_exec($curl); 

curl_close($curl); 

printf($resp); 

?>