API V8: Is there a way to retrieve attributes only and not relationships?

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?

Thanks!

Hi,
You can select only those columns which are required. Instead of selecting All or not mentioning anyone as it will load everything.

Add the fields like this

/Api/V8/module/Accounts?fields[Account]=name,account_type

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:

{
    "meta": {
        "total-pages": 10,
        "records-on-this-page": 1000
    },
    "data": [
        {
            "type": "Account",
            "id": "xxx-xxxx-xxx-xxxx",
            "attributes": {
                "name": "....",
                "website": "...",
                "email1": "..."
            },
            "relationships": {
                "AOS_Contracts": {
                    "links": {
                        "related": "..."
                    }
                },
                "AOS_Invoices": {
                    "links": {
                        "related": "..."
                    }
                },
...  

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).

Thanks!

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.

Thanks

Hi, ok great, so its not possible to do that without making it yourself.
Thanks!

Yes. As per my knowledge. May be you can use API V 4.1 as an alternate

Hey

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.

Cheers.

But v8.8 seems to be invalid. Is it because of the cache?

Maybe you need to use correct path to call an API:


Then you can clear the symfony cache and try it out.