Compose HTTP requests and handle errors

You interact with the Web API by composing and sending HTTP requests. You need to know how to set the appropriate HTTP headers and handle any errors included in the response.

Web API URL and versions

To find the Web API URL for your environment:

  1. Sign into Power Apps, and select your environment from the top-right corner.
  2. Select the Settings button in the top-right corner, and select Developer resources.

Developer resources menu

From here, you can copy the value for the Web API endpoint. More information: View developer resources

The following table describes the parts of the URL:

Part Description
Protocol https://
Environment Name The unique name that applies to your environment. If your company name is Contoso, then it may be contoso.
Region Your environment is usually in a data center that is close to you geographically. For North America, it's crm. For South America crm2, For Japan crm7. For the complete list, see Datacenter regions
Base URL This is usually, but some data centers use different values. See Datacenter regions
Web API path The path to the web API is /api/data/.
Version The version is expressed this way: v[Major_version].[Minor_version][PatchVersion]/. The current version is v9.2.
Resource The EntitySetName of the table, or the name of the function or action you want to use.

The URL you use is composed with these parts:

Protocol + Environment Name + Region + Base URL + Web API path + Version + Resource.

Version compatibility

This release introduces capabilities that aren't available in previous versions. Subsequent minor versions may provide more capabilities that won't be back ported to earlier minor versions. Your code written for v9.0 will continue to work in future versions when you reference v9.0 in the URL you use.

As new capabilities are introduced, they may conflict with earlier versions. These breaking changes are necessary to allow the service to become better. Most of the time, capabilities will remain the same between versions but you shouldn't assume they will.


Unlike the v8.x minor releases, new capabilities or other changes added to future versions will not be applied to earlier versions. You will need to pay attention to the version of the service you use and test your code if you change the version used.

HTTP methods

The following table lists the HTTP methods you can use with Dataverse Web API.

Method Usage
GET Use when retrieving data, including calling functions. The expected Status Code for a successful retrieve is 200 OK.
POST Use when creating entities or calling actions.
PATCH Use when updating entities or performing upsert operations.
DELETE Use when deleting entities or individual properties of entities.
PUT Use in limited situations to update individual properties of entities. This method isn't recommended when updating most entities. Use PUT when updating table definitions. More information: Use the Web API with table definitions

HTTP headers

All HTTP requests should include at least the following headers.

Accept: application/json  
OData-MaxVersion: 4.0  
OData-Version: 4.0
If-None-Match: null

Although the OData protocol allows for both JSON and ATOM format, the Web API only supports JSON. Every request should include the Accept header value of application/json, even when no response body is expected. Any error returned in the response is returned as JSON. While your code should work even if this header isn't included, we recommend including it as a best practice

The current OData version is 4.0, but future versions may allow for new capabilities. To ensure that there's no ambiguity about the OData version that will be applied to your code in the future, you should always include an explicit statement of the current OData version and the maximum version to apply in your code. Use both OData-Version and OData-MaxVersion headers set to a value of 4.0.

Queries that expand collection-valued navigation properties may return cached data for those properties that don't reflect recent changes. Include If-None-Match: null header in the request body to override browser caching of Web API request. More information: Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests 3.2 : If-None-Match.

Every request that includes JSON data in the request body must include a Content-Type header with a value of application/json.

Content-Type: application/json  

You can use other headers to enable specific capabilities.

Prefer Headers

You can use the Prefer header with the values below to specify preferences.

Prefer value Description
return=representation Use this preference to return data on create (POST) or update (PATCH) operations for entities. When this preference is applied to a POST request, a successful response has status 201 Created . For a PATCH request, a successful response has a status 200 OK. Without this preference applied, both operations return status 204 No Content to reflect that no data is returned in the body of the response by default. More information: Create with data returned & Update with data returned
odata.include-annotations Use this preference with the value set to OData.Community.Display.V1.FormattedValue to return formatted values with a query. More information: Include formatted values
You can also use this preference to request more error details returned by a plug-in as described in Include more details with errors below.
You can filter which annotations you want by including a wildcard character *, or you can specify to return all annotations using Prefer: odata.include-annotations="*"
odata.maxpagesize Use this preference to specify how many pages you want to return in a query. More information: Specify the number of rows to return in a page

Other headers

Header Value Description
CallerObjectId User Azure Active Directory Object ID Use this header impersonate another user when the caller has the privileges to do so. Set the value to the Azure Active Directory Object ID of the user to impersonate. This data is in the User (SystemUser) table/entity AzureActiveDirectoryObjectId attribute (column). More information: Impersonate another user using the Web API
If-Match Etag value
or *
Use this header to apply optimistic concurrency to ensure that you don't overwrite changes that someone else applied on the server since you retrieved a record. More information: Apply optimistic concurrency & If-Match
You can also use this header with * to prevent a PATCH operation from creating a record. More information: Prevent create in upsert
If-None-Match null
or *
This header should be used in all requests with a value of null as described in HTTP headers, but it can also be used to prevent a POST operation from performing an update. More information: Prevent update in upsert & If-None-Match
MSCRM.SolutionUniqueName solution unique name Use this header when you want to create a solution component and have it associated with an unmanaged solution. More information: Create and update table definitions using the Web API
MSCRM.SuppressDuplicateDetection false Use this header with the value false to enable duplicate detection when creating or updating a record. More information: Check for Duplicate records
MSCRM.BypassCustomPluginExecution true Use this header when you want to by-pass custom plug-in code and the caller has the prvBypassCustomPlugins privilege. More information: Bypass Custom Business Logic
Consistency Strong Use this header when you must have the most recent version of a cached item. Cached items include: Metadata definitions, Labels, User permissions and team permissions. For example, if you apply a change to some metadata definition, label, or permission and you have code that must use the latest definition within 30 seconds of the change, use this header to ensure you get the latest version. Using this header incurs a small performance penalty so it shouldn't be used all the time.

When you execute batch operations, you must apply many different headers in the request and with each part sent in the body. More information: Execute batch operations using the Web API.

Identify status codes

Whether an http request succeeds or fails, the response includes a status code. Status codes returned by the Microsoft Dataverse Web API include the following.

Code Description Type
200 OK Expect this status code when your operation returns data in the response body. Success
201 Created Expect this status code when your entity POST operation succeeds and you've specified the return=representation preference in your request. Success
204 No Content Expect this status code when your operation succeeds but doesn't return data in the response body. Success
304 Not Modified Expect this status code when testing whether an entity has been modified since it was last retrieved. More information: Conditional retrievals Redirection
403 Forbidden Expect this status code for the following types of errors:

- AccessDenied
- AttributePermissionReadIsMissing
- AttributePermissionUpdateIsMissingDuringUpdate
- AttributePrivilegeCreateIsMissing
- CannotActOnBehalfOfAnotherUser
- CannotAddOrActonBehalfAnotherUserPrivilege
- CrmSecurityError
- InvalidAccessRights
- PrincipalPrivilegeDenied
- PrivilegeCreateIsDisabledForOrganization
- PrivilegeDenied
- unManagedinvalidprincipal
- unManagedinvalidprivilegeedepth
Client Error
401 Unauthorized Expect this status code for the following types of errors:

- BadAuthTicket
- ExpiredAuthTicket
- InsufficientAuthTicket
- InvalidAuthTicket
- InvalidUserAuth
- MissingCrmAuthenticationToken
- MissingCrmAuthenticationTokenOrganizationName
- RequestIsNotAuthenticated
- TamperedAuthTicket
- UnauthorizedAccess
- UnManagedInvalidSecurityPrincipal
Client Error
413 Payload Too Large Expect this status code when the request length is too large. Client Error
400 BadRequest Expect this status code when an argument is invalid. Client Error
404 Not Found Expect this status code when the resource doesn't exist. Client Error
405 Method Not Allowed This error occurs for incorrect method and resource combinations. For example, you can't use DELETE or PATCH on a collection of entities.

Expect this for the following types of errors:

- CannotDeleteDueToAssociation
- InvalidOperation
- NotSupported
Client Error
412 Precondition Failed Expect this status code for the following types of errors:

- ConcurrencyVersionMismatch
- DuplicateRecord
Client Error
429 Too Many Requests Expect this status code when API limits are exceeded. More information: Service Protection API Limits Client Error
501 Not Implemented Expect this status code when some requested operation isn't implemented. Server Error
503 Service Unavailable Expect this status code when the web API service isn't available. Server Error

Parse errors from the response

Details about errors are included as JSON in the response. Errors are in this format.

  "code": "<This code is not related to the http status code and is frequently empty>",  
  "message": "<A message describing the error>"  

Include more details with errors

Some errors can include more details using annotations. When a request includes the Prefer: odata.include-annotations="*" header, the response includes all the annotations that include more details about errors and a URL that may direct you to specific guidance for the error.

Some of these details can be set by developers writing plug-ins. For example, let's say you have a plug-in that throws an error using the InvalidPluginExecutionException(OperationStatus, Int32, String) constructor. This constructor allows you to pass an OperationStatus value, a custom integer error code, and an error message.

A simple plug-in might look like this:

namespace MyNamespace
    public class MyClass : IPlugin
        public void Execute(IServiceProvider serviceProvider)

            // Obtain the tracing service
            ITracingService tracingService =

            tracingService.Trace("Entering MyClass plug-in.");

                throw new InvalidPluginExecutionException(OperationStatus.Canceled, 12345, "Example Error Message.");
            catch (InvalidPluginExecutionException ex)
                throw ex;

When this plug-in is registered on the Create message of an account entity, and the request to create an account includes the odata.include-annotations="*" preference, the request and response looks like the following:


Content-Type: application/json;
Prefer: odata.include-annotations="*"
    "name":"Example Account"


HTTP/1.1 400 Bad Request
Content-Type: application/json; odata.metadata=minimal
    "error": {
        "code": "0x80040265",
        "message": "Example Error Message.",
        "@Microsoft.PowerApps.CDS.ErrorDetails.OperationStatus": "1",
        "@Microsoft.PowerApps.CDS.ErrorDetails.SubErrorCode": "12345",
        "@Microsoft.PowerApps.CDS.HelpLink": "",
        "@Microsoft.PowerApps.CDS.TraceText": "\r\n[MyNamespace: MyNamespace.MyClass ]\r\n[52e2dbb9-85d3-ea11-a812-000d3a122b89: MyNamespace.MyClass : Create of account] \r\n\r\n Entering MyClass plug-in.\r\nStackTrace:\r\n   at MyNamespace.MyClass.Execute(IServiceProvider serviceProvider)\r\n\r\n"
        "@Microsoft.PowerApps.CDS.InnerError.Message": "Example Error Message."

This response includes the following annotations:

Annotation and Description Value
The value of the OperationStatus set by the InvalidPluginExecutionException(OperationStatus, Int32, String) constructor.
The value of the SubErrorCode set by the InvalidPluginExecutionException(OperationStatus, Int32, String) constructor.
A URL that contains information about the error that may redirect you to guidance about how to address the error.
Content written to the Plug-in trace log using the ITracingService.Trace(String, Object[]) Method. This annotation includes the stacktrace for the plugin because the plug-in author logged it.
[MyNamespace: MyNamespace.MyClass ]
[52e2dbb9-85d3-ea11-a812-000d3a122b89: MyNamespace.MyClass :Create of account]

Entering MyClass plug-in.
at MyNamespace.MyClass.Execute(IServiceProvider serviceProvider)
The error message found in the InnerError for the exception. This message should be the same as the error message except in certain special cases that are for internal use only.
Example Error Message.


The @Microsoft.PowerApps.CDS.HelpLink is not guaranteed to provide guidance for every error. Guidance may be provided proactively but most commonly it will be provided reactively based on how frequently the link is used. Please use the link. If it doesn't provide guidance, your use of the link helps us track that people need more guidance about the error. We can then prioritize including guidance to the errors that people need most. The resources that the link may direct you to may be documentation, links to community resources, or external sites.

If you don't want to receive all annotations in the response, you can specify which specific annotations you want to have returned. Rather than using Prefer: odata.include-annotations="*", you can use the following to receive only formatted values for operations that retrieve data and the helplink if an error occurs: Prefer: odata.include-annotations="OData.Community.Display.V1.FormattedValue,Microsoft.PowerApps.CDS.HelpLink".

Add a Shared Variable from the Web API

You can set a string value that is available to plug-ins within the ExecutionContext in the SharedVariables collection. More information:

See also

Perform operations using the Web API
Query data using the Web API
Create a table row using the Web API
Retrieve a table row using the Web API
Update and delete table rows using the Web API
Associate and disassociate table rows using the Web API
Use Web API functions
Use Web API actions
Execute batch operations using the Web API
Impersonate another user using the Web API
Perform conditional operations using the Web API