How can I link a contact to a opportunity via REST API?

I'm trying to find some documentation on how to do this. I will start trying to use this endpoint now, but its not clear to me if it will work:

<module>/:record/link/:link_name/:remote_id POST

But I do not know if it will work.

Thanks for some help.

  • Hello Mark,

    Let me answer with a single post on the typical question about manipulating Sugar data externally 

    Let's look at your specific task from a broader perspective of integration tasks because it's possible to avoid building out all the logic data processing by writing the code manually.
    Looks like In your case the logic is actually is a sequence of operations - to find all the contacts in CRM that meet the criteria, then to find all Opps to link them to, then perform linking

    I'm not a code developer and if you are Sugar Admin and keen to setup Sugar with no-code, it may take a few minutes to configure such things with a Logic Builder tool and then just to call it with an API call

    Below is an example that includes the logic for Contacts search (in example on Lastname and Firstname), Opps search (in example on Opp name) following Opps and Contacts linking.
    To read the logic, follow the white line:

    Logic Builder tool generates the Module Loader installable zip file from the logic drawn (zip file is provided below)

    To call the configured logic with a regular call to Sugar API, we would need to provide LinkContactToOpp endpoint definition which could be set up in CRM as a simple data record.
    For doing that just install LB Services module that allows to set up custom endpoints with no-code as module records.

    1. download LB Services from https://integroscrm.com/lb-components/ ,
    2. install LB Services with Module Loader
    3. add a record to the LB Services module with the following fields values

    4. install zip that implements the configured logic 
    z20220530_flowchart_lb6294bb52d08538_58197966.zip


    I performed the deployment sequence to the Sugar demo instance https://sg-example04.demo.sugarcrm.eu/ (login admin, password asdf)

    Now, we can use postman that Sugar instance to make REST  API call (auth, then make a POST request to LinkContactToOpp  endpoint)


    Now, all Contacts with the name "Linda Holiday" are linked to all Opportunities with the name "Opp white Cross" (you may try it out on the demo instance)

    Let me know if any questions



    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient

  • Good morning Marc.

    You are on the right track, that is the API to link two records.
    If you look at the Opportunities Vardefs in your cache folder: 

    cache/modules/Opportunities/Opportunityvardefs.php

    and search for "Contacts" you will find the definition of the link, there you will see that the link name is "contacts" (not to be confused with the relationship name which is "opportunities_contacts")

    So, once you have identified the link name, the opportunity id, and the contact id, you can easily link the two with that API.

    say your

    opportunity id = 60f2b566-30b5-11ea-8ef6-001a4a160206

    contact id = ec740bd4-fbca-11e7-8ee2-001a4a160206

    Your API call to link Contact to Opportunity:

    Opportunities/60f2b566-30b5-11ea-8ef6-001a4a160206/link/contacts/ec740bd4-fbca-11e7-8ee2-001a4a160206

     

    You could do the same starting from the Contacts module, look up the link name for Opportunities in the Contacts cache file:

    cache/modules/Contacts/Contactvardefs.php

    Identify the name of the link which is "opportunities"

    And build the API call from the Contacts:

    opportunity id = 60f2b566-30b5-11ea-8ef6-001a4a160206

    contact id = ec740bd4-fbca-11e7-8ee2-001a4a160206

    Your API call to link the Opportunity to the Contact:

    Contacts/ec740bd4-fbca-11e7-8ee2-001a4a160206/link/opportunities/60f2b566-30b5-11ea-8ef6-001a4a160206

    Hope this helps clarify that Rest API.

    FrancescaS

  • I think your end points are missing the "link/" part. Mark has this in his original post - just a small typo in your answer. At least your answer is on-topic - with the question specifically asking for help on how to use the API to do this Wink

    I believe it should be (based on your examples):

    Contacts/ec740bd4-fbca-11e7-8ee2-001a4a160206/link/opportunities/60f2b566-30b5-11ea-8ef6-001a4a160206

    That should link an existing Opportunity to the Contact record selected.

    Thanks,

    JH.