Blog

Exploring Options for Data Creation with the Dataverse Web API

Exploring Options for Data Creation with the Dataverse Web API

What is the Microsoft Dataverse Web API?

The Microsoft Dataverse Web API (Application Programming Interface) is used by Developers to integrate other platforms, applications and websites to your Dataverse or Dynamics 365 environment. It supports all CRUD (create, read, update, delete) operations to your Dataverse environment. It is a RESTful web service that supports OData, which makes it easier for Developers of different programming language backgrounds to use it.

How do you create Data with the Dataverse Web API?

Developers can use POST requests to create table rows, deep insert to create multiple related rows, and use @odata.bind to associate new rows to existing tables.

Basic Create

A basic create allows you to create a record, such as an Account, by using the entity set name, properties and values. Once the operation succeeds, a status code of OK or No Content is returned.

Create with data returned

You can extend the basic create by specifying properties to return once the record is successfully created. This is especially useful to the source system if it needs the results to complete additional requests or perform validations. This is accomplished by setting the return=representation preference in the request headers and appending the $select query option to specify which column values to return from the entity, or use $expand to return related entity data.

Create multiple records in a single request

If you have many rows of a table to create and efficiency is your priority, then you can use the CreateMultipleAction. For example, you can bulk create your Accounts in a single request. The data must be of the same entity and can be specified in your POST request as [webAPIUrl]/[entitySetName/Microsoft.Dynamics.CRM.CreateMultiple

The body will consist of a JSON array for each row of data.

Create related table rows in one operation

Using a pattern known as deep insert, you can combine multiple creation and association requests in one operation, known as atomic operation. Atomic operations will succeed only if all records were created successfully and otherwise fail, which is a good fail-safe mechanism to have! For example, you can create an Account, the primary Contact and its related Activities in one operation.

You can use the same preferences and query options as mentioned earlier to return the data that gets created.

Associate new table rows with existing table rows

Using the @odata.bind annotation with the value of navigation properties, you can create related table rows with existing data. For example, you can create child Contacts, Invoices, Orders with an existing Account.

Check for duplicate records

In Dynamics 365, there is a feature known as “Duplicate Detection Rules”. When the feature was initially released, they only executed based on end user interaction with the data to alert them of a possible duplicate record. With the Dataverse Web API, Developers can set the MSCRM.SuppressDuplicateDetection: false in the header of their POST request to enable duplicate detection using the existing Duplicate Detection Rules configured by your administrators.

Create a record from another record using column mappings

Developers can use the InitializeFrom function to retrieve values for an existing record, based on relationship column mappings configured by your administrators. The response from the Web API can then be used in a POST request when creating the new record. While this is a 2-step process for Developers, this essentially allows your integrations to mimic what end users experience when they create a child from a parent and fields are pre-populated. For example, if address fields are mapped from Account to Contact then when a new Contact is created from within an Account, the address fields are pre-populated.

Create documents in storage partitions

Microsoft has created Dataverse Elastic tables which are powered by the Azure Cosmos DB. They can be useful when the data is unstructured or semi-structured and have high volumes of input and output requests. They are not meant for data that needs to be structured, validated, consistent or complex relationships to other tables.

As you can see, Microsoft has provided Developers with many useful options for integrating data with the Dataverse. Not all options will make sense for your implementation though. It will ultimately depend on what the priorities and integration goals are. For example, you will need to consider efficiency, data structure & logic, timeline and budget.

If you’re interested in more information on these topics, take a look at our service pages for Power Platform and Azure.

Reach out to Beringer today!

We love to implement Microsoft Dynamics 365 and Power Platform solutions here at Beringer.  We’ve been working with Microsoft Dynamics since its inception, and we’re always finding innovative ways to implement the latest tools and help automate business processes.

Beringer Technology Group, a Microsoft Solutions Partner for Business Applications,  specializing in Microsoft Dynamics 365 and CRM for Distribution, also provides expert Managed IT ServicesBackup and Disaster Recovery.