AnsweredAssumed Answered

Sugar rest api using Request-Promise

Question asked by Kunal Ugale on Aug 19, 2016
Latest reply on Aug 19, 2016 by Kunal Ugale

I am trying to consume Sugar Rest API using Request-Promise. Below the sample code for doing so.

 

import sugar from 'node-sugarcrm-client';
import rp from 'request-promise';

function fetchAccounts(){
var apiURL = "http://<<suite-domain>>/service/v4_1/rest.php";

params = {
session: "<<sessionID>>",
module_name : "Accounts",
query : "",
order_by : '',
offset : '0',
select_fields : [ 'id' ,'name'],
link_name_to_fields_array : [],
max_results : -1,
deleted : '0',
Favorites : false
};
var json = JSON.stringify(params);
var body = { method: "get_entry_list", input_type: "JSON", response_type: "JSON", rest_data: json };
options = {
method: 'POST',
uri: apiURL,
body: body,
json: true
};
rp(options)
.then(function (data) {
console.log("RES: ", data);
})
.catch(function (err) {
console.log("ERR: ", err);
});
}

 

The issue is that the response I get is entire rest.php as string and not the actual JSON response.

Kindly check and let me know how I can proceed here.

Outcomes