web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Get Opporutnity ID of Contact

(0) ShareShare
ReportReport
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?
I have the same question (0)
  • Leah Ju Profile Picture
    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:
     
     
  • Community member Profile Picture
    2 on at
    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
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
DAnny3211 Profile Picture

DAnny3211 359

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 137 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 77 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans