【问题标题】:How to call Base crm REST api in php using cURL?如何使用 cURL 在 php 中调用 Base crm REST api?
【发布时间】:2014-11-24 11:58:56
【问题描述】:

我在 php 中使用 Base crm REST API 时遇到问题。

Base 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:  "));

【问题讨论】:

    标签: php api rest curl


    【解决方案1】:

    更新:Base 已发布 API V2 (https://developers.getbase.com/),以及 PHP 库:https://github.com/basecrm/basecrm-php。我建议使用它而不是下面的 sn-p。

    已经有一段时间了,但让我们试一试吧。

    对于请求和响应,我建议使用 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);
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 2014-11-15
      • 1970-01-01
      相关资源
      最近更新 更多