Hi,
When getting data from the Accounts module I noticed that it always returns the “attributes” that contains the account fields that I need, and a lot of “relationships” which I don’t need and makes the request slow and heavy, is there a way to avoid this and skip “relationships” on the request?
Hi, thanks for your reply, but sadly that is not what I was asking, in fact I’m already doing that.
As you know, in the api response when you set the fields (or not) those will come on the “attributes” field, and after that field comes the “relationships” field, like so:
What I want to know is if there is a way to avoid returning those relationships since I don’t need them and make the RQ slower (like 20 more seconds) and heavier (like 5mb).
Then a good solution is that, create your own API Endpoint. So you can take the code from existing one and override it to return the response which you want.
this is an upgrade unsafe way to do it
Go to the file Api/V8/Service/ModuleService.php
and modify the function getDataResponse as follows
public function getDataResponse(\SugarBean $bean, $fields = null, $path = null)
{
// this will be split into separated classed later
$dataResponse = new DataResponse($bean->getObjectName(), $bean->id);
$dataResponse->setAttributes($this->attributeHelper->getAttributes($bean, $fields));
// skip relationships and return
return $dataResponse;
$dataResponse->setRelationships($this->relationshipHelper->getRelationships($bean, $path));
return $dataResponse;
}
Hi @abuzarfaris thanks for your response.
I’ve reached the same conclusion, this solution does what I need, but not in the way I wanted because then I cannot choose when to get relationships or not.
Maybe this will be available at some point.