Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This .NET 6.0 sample demonstrates how to perform common data operations using the Dataverse Web API.
This sample uses the common helper code in the WebAPIService class library (C#).
Note
This sample implements the Dataverse operations and console output detailed in Web API Basic Operations Sample and uses the common C# constructs described in Web API Samples (C#).
Prerequisites
These are required to build and run this sample:
- Microsoft Visual Studio 2022.
- Access to Dataverse with privileges to perform data operations.
How to run this sample
Clone or download the PowerApps-Samples repository.
Locate the /dataverse/webapi/C#-NETx/BasicOperations/ folder.
Open the
BasicOperations.slnfile using Visual Studio 2022Edit the
appsettings.jsonfile to set the following property values:Property Instructions UrlThe Url for your environment. Replace the placeholder https://yourorg.api.crm.dynamics.comvalue with the value for your environment. See View developer resources to find the Url for your environment.UserPrincipalNameReplace the placeholder you@yourorg.onmicrosoft.comvalue with the UPN value you use to access the environment.PasswordReplace the placeholder yourPasswordvalue with the password you use.Save the
appsettings.jsonfilePress F5 to run the sample.
Code
The code for this sample is here: PowerApps-Samples/dataverse/webapi/C#-NETx/BasicOperations/Program.cs
Demonstrates
This sample has five regions:
Section 1: Basic Create and Update operations
Operations:
- Create a contact record.
- Update the contact record.
- Retrieve the contact record.
- Update a single property of the contact record.
- Retrieve a single property of the contact record.
Section 2: Create record associated to another
Operations: Associate a new record to an existing one.
Section 3: Create related entities
Operations: Create the following entries in one operation: an account, its associated primary contact, and open tasks for that contact. These entity types have the following relationships:
Accounts
|---[Primary] Contact (N-to-1)
|---Tasks (1-to-N)
Section 4: Associate and Disassociate entities
Operations:
- Add a contact to the account
contact_customer_accountscollection. - Remove a contact from the account
contact_customer_accountscollection. - Associate a security role to a user using the
systemuserroles_associationcollection. - Remove a security role for a user using the
systemuserroles_associationcollection.
Section 5: Delete sample entities
Operations: A reference to each record created in this sample was added to a list as it was created. This section loops through that list and deletes each record.
Clean up
By default this sample deletes all the records created in it. If you want to view created records after the sample is completed, change the deleteCreatedRecords variable to false and you'll be prompted to decide if you want to delete the records.
See also
Use the Dataverse Web API
WebAPIService class library (C#)
Create a table row using the Web API
Update and delete table rows using the Web API
Retrieve an table row using the Web API
Web API Samples
Web API Basic Operations Sample
Web API Query Data sample (C#)
Web API Conditional Operations sample (C#)
Web API Functions and Actions Sample (C#)
Web API table schema operations sample (C#)
Web API WebApiService Parallel Operations Sample (C#)
Web API Parallel Operations with TPL Dataflow components Sample (C#)