2017-12-28 6 views
1

私はSuiteCRMで私の最初のステップを試していて、インストールしてデータを追加して少しテストしました。suitecrm rest api with PHP

私の目標は、アプリケーションに接続したいのですが、PHPを通してREST APIを使用することです。

私はいくつかの例を見つけましたが、それは私に何も与えていないようです。 APIを使用してアプリからユーザーまたはアカウントを読み込むための例として、専門家に私に良い出発点(またはコード)を提供するよう依頼できますか?しかし、私も戻って、単一の行を持っていない

http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Examples/REST/PHP/Retrieving_a_List_of_Fields_From_a_Module/

右のURLを与え、ログイン資格情報:

私は次のリンクを試してみました。

のでFARIが行っている:API

  • でSuiteCRMインストール

    • はURLをチェックし、それはデフォルトの情報を私に戻って与えることができます。
    • 私はprint_r( "hello")を追加しました。スクリプトを実行するたびに印刷される行です。
    • このリンクを確認してください:https://suitecrm.com/forum/developer-help/7424-rest-api-documentationデフォルトのログインは運がありません。

    誰かがそれをさらにテストする方法があれば、私が学びたいと思うようにコメントを追加してください。

    EDIT:

    ここコードである:

    ますprint_r( "こんにちは")。 - これは、働いている

    $url = "http://http://demo.suiteondemand.com/service/v4_1/rest.php"; 
    $username = "will"; 
    $password = "will"; 
    
    function call($method, $parameters, $url) 
    { 
        ob_start(); 
        $curl_request = curl_init(); 
    
        curl_setopt($curl_request, CURLOPT_URL, $url); 
        curl_setopt($curl_request, CURLOPT_POST, 1); 
        curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 
        curl_setopt($curl_request, CURLOPT_HEADER, 1); 
        curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); 
        curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); 
    
        $jsonEncodedData = json_encode($parameters); 
    
        $post = array(
         "method" => $method, 
         "input_type" => "JSON", 
         "response_type" => "JSON", 
         "rest_data" => $jsonEncodedData 
        ); 
    
        curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post); 
        $result = curl_exec($curl_request); 
        curl_close($curl_request); 
    
        $result = explode("\r\n\r\n", $result, 2); 
        $response = json_decode($result[1]); 
        ob_end_flush(); 
    
        return $response; 
    } 
    
    //login ---------------------------------------- 
    $login_parameters = array(
        "user_auth" => array(
          "user_name" => $username, 
          "password" => md5($password), 
          "version" => "1" 
        ), 
        "application_name" => "RestTest", 
        "name_value_list" => array(), 
    ); 
    
    $login_result = call("login", $login_parameters, $url); 
    
    /* 
    echo "<pre>"; 
    print_r($login_result); //nothing 
    echo "</pre>"; 
    */ 
    
    //get session id 
    $session_id = $login_result->id; 
    
    //retrieve fields -------------------------------- 
    $get_module_fields_parameters = array(
    
        //session id 
        'session' => $session_id, 
    
        //The name of the module from which to retrieve records 
        'module_name' => 'Accounts', 
    
        //Optional. Returns vardefs for the specified fields. An empty array will return all fields. 
        'fields' => array(
         'id', 
         'name', 
        ), 
    ); 
    
    $get_module_fields_result = call("get_module_fields", $get_module_fields_parameters, $url); 
    
    echo "<pre>"; 
    print_r($get_module_fields_result); //nothing again 
    echo "</pre>"; 
    

    >

    私は取得していますHTMLソースは次のとおりです。

    hello<pre></pre> 
    

    ポイント:

    1. 私はデモのウェブサイトのリンクとログインを使用しています?それはうまくいくはずです(私は信じています)
    2. 私のサイトでテストしましたが、同じ結果
    3. スクリプトにエラー・メッセージ
    4. を通じてURLにも追加情報デモサイト

    のブラウザから作品ではないでしょう:

    私はデモのウェブサイトを呼び出すために管理しています...助けて、私はhttpsを持たず、HTTPとしか話していないがレンガの壁である私のウェブサイトに戻ってみたかった。私が変更したコードを見てください:

    $url = "http://my_domain.com/suiteCRM/service/v4_1/rest.php"; 
    $username = "user"; 
    $password = "pass"; 
    
    function call($method, $parameters, $url) 
    { 
        ob_start(); 
        $curl_request = curl_init(); 
    
        curl_setopt($curl_request, CURLOPT_URL, $url); 
        curl_setopt($curl_request, CURLOPT_POST, 1); 
    
  • +1

    をあなたのコードを見ずに何も言うことはできません。しかし、http://www.urdhva-tech.com/blogs/sugarcrm-rest-api-example例は間違いなく助けになります。私は以前にそれを使用しました。 –

    +0

    こんにちは、ヒントのおかげで多くの。私は "エラー処理結果"を受け取りました。デモのウェブサイトのメッセージ、それはまたv2です。あなたは最近それに運があったのですか? –

    答えて

    2

    ああ、あなたは間違っているとは思っていませんでしたが、タイプミスがありました。休憩の終点のURLを確認してください。適切な構造でHTTPSを指す必要があります。(私のために正常に動作)が更新され、次のコード:

    $url = "https://demo.suiteondemand.com/service/v4_1/rest.php"; 
    $username = "will"; 
    $password = "will"; 
    
    function call($method, $parameters, $url) 
    { 
        ob_start(); 
        $curl_request = curl_init(); 
    
        curl_setopt($curl_request, CURLOPT_URL, $url); 
        curl_setopt($curl_request, CURLOPT_POST, 1); 
        curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); 
        curl_setopt($curl_request, CURLOPT_HEADER, 1); 
        curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0); 
        curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0); 
    
        $jsonEncodedData = json_encode($parameters); 
    
        $post = array(
         "method" => $method, 
         "input_type" => "JSON", 
         "response_type" => "JSON", 
         "rest_data" => $jsonEncodedData 
        ); 
    
        curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post); 
        $result = curl_exec($curl_request); 
        curl_close($curl_request); 
    
        $result = explode("\r\n\r\n", $result, 2); 
        $response = json_decode($result[1]); 
        ob_end_flush(); 
    
        return $response; 
    } 
    
    //login ---------------------------------------- 
    $login_parameters = array(
        "user_auth" => array(
          "user_name" => $username, 
          "password" => md5($password), 
          "version" => "1" 
        ), 
        "application_name" => "RestTest", 
        "name_value_list" => array(), 
    ); 
    
    $login_result = call("login", $login_parameters, $url); 
    
    /* 
    echo "<pre>"; 
    print_r($login_result); //nothing 
    echo "</pre>"; 
    */ 
    
    //get session id 
    $session_id = $login_result->id; 
    
    //retrieve fields -------------------------------- 
    $get_module_fields_parameters = array(
    
        //session id 
        'session' => $session_id, 
    
        //The name of the module from which to retrieve records 
        'module_name' => 'Accounts', 
    
        //Optional. Returns vardefs for the specified fields. An empty array will return all fields. 
        'fields' => array(
         'id', 
         'name', 
        ), 
    ); 
    
    $get_module_fields_result = call("get_module_fields", $get_module_fields_parameters, $url); 
    
    echo "<pre>"; 
    print_r($get_module_fields_result); //nothing again 
    echo "</pre>"; 
    

    それは次のような出力を生成:

    stdClass Object 
    (
        [module_name] => Accounts 
        [table_name] => accounts 
        [module_fields] => stdClass Object 
         (
          [id] => stdClass Object 
           (
            [name] => id 
            [type] => id 
            [group] => 
            [id_name] => 
            [label] => ID 
            [required] => 1 
            [options] => Array 
             (
             ) 
    
            [related_module] => 
            [calculated] => 
            [len] => 
           ) 
    
          [name] => stdClass Object 
           (
            [name] => name 
            [type] => name 
            [group] => 
            [id_name] => 
            [label] => Name: 
            [required] => 1 
            [options] => Array 
             (
             ) 
    
            [related_module] => 
            [calculated] => 
            [len] => 150 
           ) 
    
         ) 
    
        [link_fields] => Array 
         (
         ) 
    
    ) 
    
    +0

    もう一度!あなたの手がかりに感謝します。私のウェブサイトはHTTPSを持っていないので、動作しません。その周りに道がありますか?事前に多くの感謝。 –

    +0

    は単にURLをHTTPSからHTTPに変更します。うまくいけばそれはあなたのために働くでしょう。 – Star

    +0

    httpとIPアドレスを試してみて、同じ情報が得られていないことに多くの感謝をします。これはSSLまたは私のインストールかもしれません...私はまだ分かりません。 –