Skip to main content

Notifications

Announcements

No record found.

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?
  • 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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,082 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,870 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans