2017-12-28 2 views
1

SuiteCRM에서 첫 걸음을 내딛었습니다. 설치하고 관리하고 데이터를 추가하고 테스트 해 보았습니다.suitecrm rest phi 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을 제공하고 로그인 자격 증명 :

나는 다음과 같은 링크를 시도했다.

  • 이 URL을 확인

    • 은 API와 SuiteCRM를 설치하고 기본 정보를 나에게 돌려 줄 수 있습니다

      그래서 FARI을 수행했다.

    • print_r ("hello")를 추가했습니다. 스크립트를 실행할 때마다 인쇄되는 줄.
    • 이 링크를 확인하십시오 : 행운을 뺀 기본 로그인 인 https://suitecrm.com/forum/developer-help/7424-rest-api-documentation.

    누구든지 더 테스트 할 방법이 있다면 배우고 싶은대로 의견을 추가하십시오.

    편집 : 여기

    코드이다

    에서 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. 스크립트 것없는 오류 메시지의 URL도 데모 사이트에 브라우저에서 작동
    4. 통해

    추가 정보 : 내가 함께 데모 웹 사이트를 호출 관리해야

    ... 도움이되어서 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 또는 제 설치 일 수 있습니다 ... 나는 아직 모릅니다. –