2016-12-07 3 views
0

레코드 목록 뷰에 추가 작업을 추가했습니다. SugarCRM : REST 엔드 포인트에서 json 데이터를 가져 오는 방법

custom/modules/Opportunities/clients/base/views/recordlist/recordlist.js:

({ 
    extendsFrom: 'RecordlistView', 

    initialize: function(options) { 
     this._super("initialize", [options]); 
     //add listener for custom button 
     this.context.on('list:opportunitiesexport2:fire', this.export2, this); 
    }, 
    export2: function() { 
     //gets an array of ids of all selected opportunities 
     var selected = this.context.get("mass_collection").pluck('id'); 
     if (selected) { 
      return App.api.call('read', 
      App.api.buildURL('Opportunities/Export2'), 
      {'selected_ids':selected}, 
      { 
       success: function(response) { 
        console.log("SUCCESS"); 
        console.log(response); 
       }, 
       error: function(response) { 
        console.log('ERROR'); 
        console.log(response); 
       }, 
       complete: function(response){ 
        console.log("COMPLETE"); 
        console.log(response); 
       }, 
       error: function(response){ 
        console.log("ERROR"); 
        console.log(response); 
       } 
      }); 
     } 
    }, 
}) 

여기 http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Integration/Web_Services/v10/Extending_Endpoints/ 튜토리얼은 엔드 포인트를 작성하는 방법을 설명합니다.

그러나 json 데이터 (선택된 ID의 문자열로 정렬 된 배열)를 얻는 방법은 설명하지 않습니다.

custom/modules/Opportunities/clients/base/api/OpportunitiesApi.php:

class OpportunitiesApi extends SugarApi 
{ 
    public function registerApiRest() 
    { 
     return array(
      //GET 
      'MyGetEndpoint' => array(
       //request type 
       'reqType' => 'GET', 

       //set authentication 
       'noLoginRequired' => false, 

       //endpoint path 
       'path' => array('Opportunities', 'Export2'), 

       //endpoint variables 
       'pathVars' => array('', ''), 

       //method to call 
       'method' => 'Export2', 

       //short help string to be displayed in the help documentation 
       'shortHelp' => 'Export', 

       //long help to be displayed in the help documentation 
       'longHelp' => 'custom/clients/base/api/help/MyEndPoint_MyGetEndPoint_help.html', 
      ), 
     ); 
    } 

    /** 
    * Method to be used for my MyEndpoint/GetExample endpoint 
    */ 
    public function Export2($api, $args) 
    { 
     //how to access $args['selected_ids']? 
    } 
} 

$args

Array 
(
    [__sugar_url] => v10/Opportunities/Export2 
) 

는 JSON 데이터를 액세스 할 수 있습니다 포함?

답변

0

해결 방법은 호출 방법을 create으로 변경하고 끝점 방법을 POST으로 변경하는 것입니다. 난 아무것도 변경할 계획하지 않았기 때문에 내가 GET을 사용했지만, 몸은 일반적으로 GET 요청에서 무시됩니다 - $args 지금

Array 
(
    [selected_ids] => Array 
     (
      [0] => 0124a524-accc-11e6-96a8-005056897bc3 
     ) 

    [__sugar_url] => v10/Opportunities/Export2 
) 

PUT vs POST in REST가 포함되어 있습니다.

0

나는 똑같이했으나 내 나머지 API는 자바로 코딩되어 있었다. 내 get 메소드에 주석을 달기 위해 java @Path annotation을 사용했다. 그런 다음 나머지 api 코드를 서버 (Tomcat의 경우)에 배포했습니다. 서버를 시작한 다음 @Path로 구성된 URL을 누르면 브라우저의 json 데이터가 제공됩니다.