Skip to content

Instantly share code, notes, and snippets.

@elchele
Created June 28, 2019 01:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elchele/cb9320c8987121ab4a0db7a5443dd918 to your computer and use it in GitHub Desktop.
Save elchele/cb9320c8987121ab4a0db7a5443dd918 to your computer and use it in GitHub Desktop.
<?php
/* File: ./custom/clients/base/api/MyCustomApi.php */
class MyCustomApi extends SugarApi {
public function registerApiRest() {
return array(
'myCustomMethod' => array(
'reqType' => 'GET',
'path' => array('customEndpoint'),
'pathVars' => array(),
'method' => 'myCustomMethod',
'shortHelp' => 'This is a custom endpoint.',
'longHelp' => '',
)
);
}
public function myCustomMethod($api, $args)
{
//Some code
//Here we raise the exception with our custom error message
throw new SugarApiExceptionMissingParameter('You are missing a parameter required for properly invoking this endpoint.');
//the rest of your code for your custom method
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment