Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Get Opporutnity ID of Contact

Posted on by 2
Hi, I want to fetch a contact's opportunity Id using APIs. Is there any way I can get opportunity id if I have the contact id? 
I need to update the opportunity but I only have the contact Id. So if I can get the opportunity Id I can update the opportunity. 
If there is a way kindly let me know what endpoint should I use and hit to get the opportunity Id?
  • Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Get Opporutnity ID of Contact
    Hi Partner,
    Based on the documentation you provided, the app you are using is Business Central?
    If so, you need post questions on the following forum:
     
     
  • Get Opporutnity ID of Contact
    So I need to build an API to get what I want? The API's that are provided by MS Dynamics, does none of them can carry out this request? Like the get opportunity request or any CRUD like https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_opportunity_get ?
     
    I am using a 3rd party tool to make requests. My end goal is to update the opportunity when I update a contact.
    So at the moment of contact update I won't have the opportunity ID, to get that I would need make another request to get all opportunity IDs of that contact and then update them. I would prefer to use the api's listed in documentation. Is it possible in any of those APIs?
  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Get Opporutnity ID of Contact
    Hi partner,
    One contact has many related opportunities through one-to-many relationship between them, if you have the contact id, you can get opportunities related to it.
    So you can build web api as following:
    Xrm.WebApi.retrieveMultipleRecords("opportunity", "?$select=opportunityid&$filter=(_contactid_value eq 25a17064-1ae7-e611-80f4-e0071b661f01 or _parentcontactid_value eq 25a17064-1ae7-e611-80f4-e0071b661f01)").then(
    	function success(results) {
    		console.log(results);
    		for (var i = 0; i < results.entities.length; i++) {
    			var result = results.entities[i];
    			// Columns
    			var opportunityid = result["opportunityid"]; // Guid
    		}
    	},
    	function(error) {
    		console.log(error.message);
    	}
    );
    Result:
    Note: 'Dataverse REST Builder' tools help you build api easily, https://github.com/GuidoPreite/DRB
    I hope you can verify my answer if it helps you! If you have any questions, please feel free to contact me.
    Regards,
    Leah

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans