Whats wrong with this custom API class?

Hi, I am starting to develop custom API regarding multiple pieces of information we need.  I wanted to just see if I can get the example on sugar developer site to work, but I got this error. Could not find a route with 2 elements

<?php

if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

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

   //set authentication
   'noLoginRequired' => false,

   //endpoint path
   'path' => array('MyEndpoint', 'GetExample', '?'),

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

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

   //short help string to be displayed in the help documentation
   'shortHelp' => 'An example of a GET endpoint',

   //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 MyGetMethod($api, $args)
   {
   //custom logic
   return $args;
   }

}

?>

 

 

I am using postman to do the api calls faster. Am I doing this right?

 

Thanks in advance

Parents
  • You defined a path with 3 segments, one of which is a variable.

    MyEndpoint/GetExample/{variable}

    So if you modified your call to hit

    MyEndpoint/GetExample/1234

    Then this endpoint would work.

    If what you meant to do was define a path with only 2 segments and then accepts URL arguments. (?test=1234&etc=...)

    Modify your path as follows and it should work correctly with your existing HTTP request.

       //endpoint path

       'path' => array('MyEndpoint', 'GetExample'),

       //endpoint variables

       'pathVars' => array('', ''),

    App Ecosystem @ SugarCRM

Reply
  • You defined a path with 3 segments, one of which is a variable.

    MyEndpoint/GetExample/{variable}

    So if you modified your call to hit

    MyEndpoint/GetExample/1234

    Then this endpoint would work.

    If what you meant to do was define a path with only 2 segments and then accepts URL arguments. (?test=1234&etc=...)

    Modify your path as follows and it should work correctly with your existing HTTP request.

       //endpoint path

       'path' => array('MyEndpoint', 'GetExample'),

       //endpoint variables

       'pathVars' => array('', ''),

    App Ecosystem @ SugarCRM

Children