AnsweredAssumed Answered

SugarCRM 7 create custom Rest Api with Post method and call from record.js using App.api.call

Question asked by Atif Hussain on Aug 23, 2016
Latest reply on Aug 23, 2016 by Atif Hussain

I am creating a custom Rest v10 endpoint. I have created an API accepting GET method of request. Now I need to create an API with POST method, and send it data from my record.js file, which I have extended from contacts module. 

My API code is as following. 

 

My API is placed in:

custom\clients\base\api\MyContactsAPI.php

public function registerApiRest()
{
return array(
//GET
'MyContactsAPI' => array(
//request type
'reqType' => 'GET',

//set authentication
'noLoginRequired' => true,

//endpoint path
'path' => array('MyContactsAPI', 'GetData', '?'),
//endpoint variables
'pathVars' => array('', '', 'data'),
//method to call
'method' => 'GetDuplicates',
//short help string to be displayed in the help documentation
'shortHelp' => 'An API to get activity report of an account and all its related modules',
//long help to be displayed in the help documentation
'longHelp' => 'custom/clients/base/api/help/MyEndPoint_MyGetEndPoint_help.html',
),
);
}
public function GetData($api, $args)
{
   // logic will be here
}

Now I don't know, how to convert the same API to accept POST requests and how to call it from record.js file using App.api.call and sending JSON data to API. 

 

Any help will be appriciated. 

Outcomes