Question about using the rest API with related records


I have successfully been able to create related records using the /<module>/:record/link/:link_name POST endpoint.

And I have successfully been able to list all of the related records to a specific record using the /<module>/:record/link/:link_name GET endpoint.

However I have not been able to find in the documentation a way to list all of the related records between two modules?  Say that I wanted to retrieve all of the links between accounts and projects.  How would I be able to do that?


Bryan Hunt

  • , you'll want to use the Metadata API to obtain the details you are looking for. Start with this article

  • Jeff, 

    Thanks for the response.  But this isn't quite what I was looking for.

    I want to see the actual link records for every account that is linked to a project.  Somewhere there must be a table of all record linkages?


    Bryan Hunt

  • Hi Bryan,

    I believe you'd like to retrieve the Many-To-Many record that ties 2 modules together huh?

    The underlying structure of tables is all handled by Sugar and there's no API for it, you could definitely write your own Sugar Query for that but I'd like to understand your requirement first. 

    It's very unusual for you to manipulate that join table yourself other than the following methods:

    Please share your requirements with us, perhaps there's a better way of doing this:

    GET /<module>/:record/link/:link_name | Retrieve a module's records related to another
    module's record
    /<module>/:record/link/:link_name/:remote_id | Relate a module's record to another module's
    /<module>/:record/link/:link_name/:remote_id | Delete a relationship between two module’s


    SugarCRM | Principal Developer Advocate

  • Rafael,

    The end in mind is to save on api calls. We batch process a bunch of records every night and we need to make sure that we have links between them. If links already exist, great. If not, we need to create new ones.

    I could execute a GET /<module>/:record/link/:link_name endpoint api call for every record combination, but would explode the number of api calls that we make for these processes.

    A better solution would be to bulk-read all of the existing links between the two modules and then do lookups in memory to see if existing links are present. That would save greatly on api calls. I just don't seem to be able to find an endpoint that would give me linkage records in bulk.

    Experimentation with adding link records seems to indicate that if I POST a link that already exists it does not duplicate, it simply ignores the POST and returns a OK result. So I will probably just skip the check-for-existing-links step and just POST all combinations of record links. Not my preferred approach, but probably the cheapest (in terms of API calls) in the long run.


    Bryan Hunt