Skip to content

Commit 96e682d

Browse files
authored
Merge pull request #6223 from MicrosoftDocs/jdaly-main-2630924
Jdaly main 2630924
2 parents 7899ace + 45d9f3b commit 96e682d

File tree

1 file changed

+59
-37
lines changed

1 file changed

+59
-37
lines changed

powerapps-docs/developer/data-platform/webapi/query-data-web-api.md

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Query data using the Web API (Microsoft Dataverse)| Microsoft Docs"
3-
description: "Read about the various ways to query Microsoft Dataverse table data using the Web API and the various system query options that can be applied in these queries."
4-
ms.date: 04/08/2022
3+
description: "Learn how to query Microsoft Dataverse table data using the Web API and the options that can be applied in these queries."
4+
ms.date: 04/18/2022
55
author: divka78
66
ms.author: dikamath
77
ms.reviewer: jdaly
@@ -30,7 +30,7 @@ If you want to retrieve data for an entity set, use a `GET` request. When retrie
3030
**Request**
3131

3232
```http
33-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
33+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
3434
&$top=3 HTTP/1.1
3535
Accept: application/json
3636
OData-MaxVersion: 4.0
@@ -46,7 +46,7 @@ Content-Type: application/json; odata.metadata=minimal
4646
OData-Version: 4.0
4747
4848
{
49-
"@odata.context":"[Organization URI]/api/data/v9.1/$metadata#accounts(name)",
49+
"@odata.context":"[Organization URI]/api/data/v9.2/$metadata#accounts(name)",
5050
"value":[
5151
{
5252
"@odata.etag":"W/\"501097\"",
@@ -84,7 +84,7 @@ OData-Version: 4.0
8484
You can limit the number of results returned by using the `$top` system query option. The following example will return just the first three account rows.
8585

8686
```http
87-
GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue&$top=3
87+
GET [Organization URI]/api/data/v9.2/accounts?$select=name,revenue&$top=3
8888
```
8989

9090
> [!NOTE]
@@ -106,7 +106,7 @@ Use the `odata.maxpagesize` preference value to request the number of rows retur
106106
**Request**
107107

108108
```http
109-
GET [Organization URI]/api/data/v9.1/accounts?$select=name HTTP/1.1
109+
GET [Organization URI]/api/data/v9.2/accounts?$select=name HTTP/1.1
110110
Accept: application/json
111111
OData-MaxVersion: 4.0
112112
OData-Version: 4.0
@@ -123,7 +123,7 @@ Content-Length: 402
123123
Preference-Applied: odata.maxpagesize=3
124124
125125
{
126-
"@odata.context":"[Organization URI]/api/data/v9.1/$metadata#accounts(name)",
126+
"@odata.context":"[Organization URI]/api/data/v9.2/$metadata#accounts(name)",
127127
"value":[
128128
{
129129
"@odata.etag":"W/\"437194\"",
@@ -141,7 +141,7 @@ Preference-Applied: odata.maxpagesize=3
141141
"accountid":"8151925c-cde2-e411-80db-00155d2a68cb"
142142
}
143143
],
144-
"@odata.nextLink":"[Organization URI]/api/data/v9.1/accounts?$select=name&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%253e%253caccountid%2520last%253d%2522%257b8151925C-CDE2-E411-80DB-00155D2A68CB%257d%2522%2520first%253d%2522%257b7D51925C-CDE2-E411-80DB-00155D2A68CB%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20/%3E"
144+
"@odata.nextLink":"[Organization URI]/api/data/v9.2/accounts?$select=name&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%253e%253caccountid%2520last%253d%2522%257b8151925C-CDE2-E411-80DB-00155D2A68CB%257d%2522%2520first%253d%2522%257b7D51925C-CDE2-E411-80DB-00155D2A68CB%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20/%3E"
145145
}
146146
147147
```
@@ -158,7 +158,7 @@ Preference-Applied: odata.maxpagesize=3
158158
Each of the system query options you append to the URL for the entity set is added using the syntax for query strings. The first is appended after [?] and subsequent query options are separated using [&]. All query options are case-sensitive as shown in the following example.
159159

160160
```http
161-
GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue
161+
GET [Organization URI]/api/data/v9.2/accounts?$select=name,revenue
162162
&$top=3
163163
&$filter=revenue gt 100000
164164
```
@@ -170,15 +170,15 @@ GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue
170170
Use the `$select` system query option to limit the properties returned as shown in the following example.
171171

172172
```http
173-
GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue
173+
GET [Organization URI]/api/data/v9.2/accounts?$select=name,revenue
174174
```
175175

176176
> [!IMPORTANT]
177177
> This is a performance best practice. If properties aren’t specified using `$select`, all properties will be returned.
178178
179179
When you request certain types of properties you can expect additional read-only properties to be returned automatically.
180180

181-
If you request a money value, the `_transactioncurrencyid_value` lookup property will be returned. This property contains only the GUID value of the transaction currency so you could use this value to retrieve information about the currency using the <xref:Microsoft.Dynamics.CRM.transactioncurrency?text=transactioncurrency EntityType />. Alternatively, by requesting annotations you can also get additional data in the same request. More information: [Retrieve data about lookup properties](#bkmk_lookupProperty)
181+
If you request a money value, the `_transactioncurrencyid_value` lookup property will be returned. This property contains only the GUID value of the transaction currency so you could use this value to retrieve information about the currency using the <xref:Microsoft.Dynamics.CRM.transactioncurrency?text=transactioncurrency EntityType>. Alternatively, by requesting annotations you can also get additional data in the same request. More information: [Retrieve data about lookup properties](#bkmk_lookupProperty)
182182

183183
If you request a property that is part of a composite attribute for an address, you will get the composite property as well. For example, if your query requests the `address1_line1` property for a contact, the `address1_composite` property will be returned as well.
184184

@@ -236,10 +236,10 @@ You can use wildcard characters when you construct queries using these standard
236236

237237
### Microsoft Dataverse Web API query functions
238238

239-
Dataverse provides a number of special functions that accept parameters, return Boolean values, and can be used as filter criteria in a query. See <xref:Microsoft.Dynamics.CRM.QueryFunctionIndex?displayProperty=nameWithType> for a list of these functions. The following is an example of the <xref:Microsoft.Dynamics.CRM.Between?text=Between Function /> searching for accounts with a number of employees between 5 and 2000.
239+
Dataverse provides a number of special functions that accept parameters, return Boolean values, and can be used as filter criteria in a query. See <xref:Microsoft.Dynamics.CRM.QueryFunctionIndex?displayProperty=nameWithType> for a list of these functions. The following is an example of the <xref:Microsoft.Dynamics.CRM.Between?text=Between Function> searching for accounts with a number of employees between 5 and 2000.
240240

241241
```http
242-
GET [Organization URI]/api/data/v9.1/accounts?$select=name,numberofemployees
242+
GET [Organization URI]/api/data/v9.2/accounts?$select=name,numberofemployees
243243
&$filter=Microsoft.Dynamics.CRM.Between(PropertyName='numberofemployees',PropertyValues=["5","2000"])
244244
```
245245

@@ -262,7 +262,7 @@ The `any` operator returns `true` if the Boolean expression applied is `true` fo
262262
The example given below shows how you can retrieve all account entity records that have at least one email with "sometext" in the subject.
263263

264264
```http
265-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
265+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
266266
&$filter=Account_Emails/any(o:contains(o/subject,'sometext')) HTTP/1.1
267267
Prefer: odata.include-annotations="*"
268268
Accept: application/json
@@ -281,7 +281,7 @@ The `all` operator returns `true` if the Boolean expression applied is `true` fo
281281
The example given below shows how you can retrieve all account entity records that have all associated tasks closed.
282282

283283
```http
284-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
284+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
285285
&$filter=Account_Tasks/all(o:o/statecode eq 1) HTTP/1.1
286286
Prefer: odata.include-annotations="*"
287287
Accept: application/json
@@ -292,7 +292,7 @@ OData-Version: 4.0
292292
The example given below shows how you can retrieve all account entity records that have at least one email with "sometext" in the subject and whose statecode is active.
293293

294294
```http
295-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
295+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
296296
&$filter=Account_Emails/any(o:contains(o/subject,'sometext') and
297297
o/statecode eq 0) HTTP/1.1
298298
Prefer: odata.include-annotations="*"
@@ -304,7 +304,7 @@ OData-Version: 4.0
304304
The example given below shows how you can also create a nested query using `any` and `all` operators.
305305

306306
```http
307-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
307+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
308308
&$filter=(contact_customer_accounts/any(c:c/jobtitle eq 'jobtitle' and
309309
c/opportunity_customer_contacts/any(o:o/description ne 'N/A'))) and
310310
endswith(name,'{0}') HTTP/1.1
@@ -325,7 +325,7 @@ The example given below shows how you can use the [/any operator](#bkmk_anyopera
325325
**Request**
326326

327327
```http
328-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
328+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
329329
&$filter=not opportunity_customer_accounts/any(o:o/description eq null and
330330
o/budgetamount le 300 or
331331
contains(o/description, 'bad')) and
@@ -351,7 +351,7 @@ For example:
351351
**Request**
352352

353353
```http
354-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
354+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
355355
&$filter=primarycontactid/contactid eq a0dbf27c-8efb-e511-80d2-00155db07c77 HTTP/1.1
356356
Accept: application/json
357357
OData-MaxVersion: 4.0
@@ -366,7 +366,7 @@ Content-Type: application/json; odata.metadata=minimal
366366
OData-Version: 4.0
367367
368368
{
369-
"@odata.context":"[Organization URI]/api/data/v9.1/$metadata#accounts(name)",
369+
"@odata.context":"[Organization URI]/api/data/v9.2/$metadata#accounts(name)",
370370
"value":[
371371
{
372372
"@odata.etag":"W/\"513479\"",
@@ -387,7 +387,7 @@ OData-Version: 4.0
387387
**Request**
388388

389389
```http
390-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
390+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
391391
&$filter=parentaccountid/accountid eq 3adbf27c-8efb-e511-80d2-00155db07c77
392392
Accept: application/json
393393
OData-MaxVersion: 4.0
@@ -402,7 +402,7 @@ Content-Type: application/json; odata.metadata=minimal
402402
OData-Version: 4.0
403403
404404
{
405-
"@odata.context":"[Organization URI]/api/data/v9.1/$metadata#accounts(name)",
405+
"@odata.context":"[Organization URI]/api/data/v9.2/$metadata#accounts(name)",
406406
"value":[
407407
{
408408
"@odata.etag":"W/\"514058\"",
@@ -430,7 +430,7 @@ The two options for filtering results based on values of collection-valued navig
430430
Lambda operators allow you to apply filter on values of collection properties for a link-entity. The below example retrieves the records of `systemuser` entity type that are linked with `team` and `teammembership` entity types, that means it retrieves `systemuser` records who are also administrators of a team whose name is "CITTEST".
431431

432432
```http
433-
GET [Organization URI]/api/data/v9.1/systemusers?$filter=(teammembership_association/any(t:t/name eq 'CITTEST'))
433+
GET [Organization URI]/api/data/v9.2/systemusers?$filter=(teammembership_association/any(t:t/name eq 'CITTEST'))
434434
&$select=fullname,businessunitid,title,address1_telephone1,systemuserid
435435
&$orderby=fullname
436436
Accept: application/json
@@ -446,10 +446,32 @@ To get the same results as the example above, you can retrieve records of two en
446446
Follow the steps in the below example to understand how we can filter results using the iteration method:
447447

448448
1. Get a distinct list of <xref:Microsoft.Dynamics.CRM.team?displayProperty=nameWithType>._administratorid_value values.
449-
- `GET [OrganizationURI]/api/data/v9.1/teams?$select=_administratorid_value&$filter=_administrator_value ne null`
449+
- `GET [OrganizationURI]/api/data/v9.2/teams?$select=_administratorid_value&$filter=_administrator_value ne null`
450450
- Then loop through the returned values to remove duplicates and get a distinct list. i.e. Create a new array, loop through the query results, for each check to see if they are already in the new array, if not, add them. This should give you a list of distinct `systemuserid` values
451451
- The way you would do this in JavaScript vs C# would be different, but essentially you should be able to get the same results.
452-
2. Query <xref:Microsoft.Dynamics.CRM.systemuser?displayProperty=nameWithType> using <xref:Microsoft.Dynamics.CRM.ContainValues?text=ContainValues Query Function /> to compare the `systemuserid` values with the list collected in Step 1.
452+
2. Query <xref:Microsoft.Dynamics.CRM.systemuser?displayProperty=nameWithType> using <xref:Microsoft.Dynamics.CRM.ContainValues?text=ContainValues Query Function> to compare the `systemuserid` values with the list collected in Step 1.
453+
454+
### Manage single quotes in string filter values
455+
456+
When specifying values for comparison in filters that accept an array of string values, such as the <xref:Microsoft.Dynamics.CRM.In?text=In Query Function>, which contain single quote (apostrophe) characters, such as `O'Brian` or `Men's clothes` you must use double quotes around the values. For example:
457+
458+
```http
459+
GET [Organization URI]/api/data/v9.2/contacts?$select=fullname
460+
&$filter=Microsoft.Dynamics.CRM.In(PropertyName=@p1,PropertyValues=@p2)
461+
&@p1='lastname'
462+
&@p2=["OBrian","OBryan","O'Brian","O'Bryan"]
463+
```
464+
465+
Otherwise you will get the following error: `Invalid JSON. A comma character ',' was expected in scope 'Array'. Every two elements in an array and properties of an object must be separated by commas.`
466+
467+
If the filter is for a single value, replace the single quote character with two consecutive single quote characters. For example:
468+
469+
```http
470+
GET [Organization URI]/api/data/v9.2/contacts?$select=fullname
471+
&$filter=lastname eq 'O''Bryan'
472+
```
473+
474+
Otherwise you will get an error like the following: `There is an unterminated literal at position 21 in 'lastname eq 'O'Bryan''.`
453475

454476
<a name="bkmk_order"></a>
455477

@@ -458,7 +480,7 @@ Follow the steps in the below example to understand how we can filter results us
458480
Specify the order in which items are returned using the `$orderby` system query option. Use the `asc` or `desc` suffix to specify ascending or descending order respectively. The default is ascending if the suffix isn’t applied. The following example shows retrieving the name and revenue properties of accounts ordered by ascending revenue and by descending name.
459481

460482
```http
461-
GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue
483+
GET [Organization URI]/api/data/v9.2/accounts?$select=name,revenue
462484
&$orderby=revenue asc,name desc
463485
&$filter=revenue ne null
464486
```
@@ -493,15 +515,15 @@ Additional details on OData data aggregation can be found here: [OData extension
493515
Without parameter aliases:
494516

495517
```http
496-
GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue
518+
GET [Organization URI]/api/data/v9.2/accounts?$select=name,revenue
497519
&$orderby=revenue asc,name desc
498520
&$filter=revenue ne null
499521
```
500522

501523
With parameter aliases:
502524

503525
```http
504-
GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue
526+
GET [Organization URI]/api/data/v9.2/accounts?$select=name,revenue
505527
&$orderby=@p1 asc,@p2 desc
506528
&$filter=@p1 ne @p3&@p1=revenue&@p2=name
507529
```
@@ -517,7 +539,7 @@ GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue
517539
> [!NOTE]
518540
> The count value does not represent the total number of rows in the system. It is limited by the maximum number of rows that can be returned. More information: [Limits on number of rows returned](#bkmk_limits)
519541
>
520-
> If you want to retrieve the total number of rows for a table beyond 5000, use the <xref:Microsoft.Dynamics.CRM.RetrieveTotalRecordCount?text=RetrieveTotalRecordCount Function />.
542+
> If you want to retrieve the total number of rows for a table beyond 5000, use the <xref:Microsoft.Dynamics.CRM.RetrieveTotalRecordCount?text=RetrieveTotalRecordCount Function>.
521543
522544
The response `@odata.count` property will contain the number of rows that match the filter criteria irrespective of an `odata.maxpagesize` preference limitation.
523545

@@ -529,7 +551,7 @@ GET [Organization URI]/api/data/v9.1/accounts?$select=name,revenue
529551
**Request**
530552

531553
```http
532-
GET [Organization URI]/api/data/v9.1/accounts?$select=name
554+
GET [Organization URI]/api/data/v9.2/accounts?$select=name
533555
&$filter=contains(name,'sample')
534556
&$count=true HTTP/1.1
535557
Accept: application/json
@@ -547,7 +569,7 @@ OData-Version: 4.0
547569
Preference-Applied: odata.maxpagesize=3
548570
549571
{
550-
"@odata.context":"[Organization URI]/api/data/v9.1/$metadata#accounts(name)",
572+
"@odata.context":"[Organization URI]/api/data/v9.2/$metadata#accounts(name)",
551573
"@odata.count":10,
552574
"value":[
553575
{
@@ -566,7 +588,7 @@ Preference-Applied: odata.maxpagesize=3
566588
"accountid":"695eaf89-f083-e511-80d3-00155d2a68d3"
567589
}
568590
],
569-
"@odata.nextLink":"[Organization URI]/api/data/v9.1/accounts?$select=name&$filter=contains(name,'sample')&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%253e%253caccountid%2520last%253d%2522%257b695EAF89-F083-E511-80D3-00155D2A68D3%257d%2522%2520first%253d%2522%257b655EAF89-F083-E511-80D3-00155D2A68D3%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E"
591+
"@odata.nextLink":"[Organization URI]/api/data/v9.2/accounts?$select=name&$filter=contains(name,'sample')&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%253e%253caccountid%2520last%253d%2522%257b695EAF89-F083-E511-80D3-00155D2A68D3%257d%2522%2520first%253d%2522%257b655EAF89-F083-E511-80D3-00155D2A68D3%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E"
570592
}
571593
572594
@@ -577,7 +599,7 @@ Preference-Applied: odata.maxpagesize=3
577599
**Request**
578600

579601
```http
580-
GET [Organization URI]/api/data/v9.1/accounts/$count HTTP/1.1
602+
GET [Organization URI]/api/data/v9.2/accounts/$count HTTP/1.1
581603
Accept: application/json
582604
OData-MaxVersion: 4.0
583605
OData-Version: 4.0
@@ -606,7 +628,7 @@ OData-Version: 4.0
606628
**Request**
607629

608630
```http
609-
GET [Organization URI]/api/data/v9.1/accounts?$select=name,donotpostalmail,accountratingcode,numberofemployees,revenue
631+
GET [Organization URI]/api/data/v9.2/accounts?$select=name,donotpostalmail,accountratingcode,numberofemployees,revenue
610632
&$top=1 HTTP/1.1
611633
Accept: application/json
612634
OData-MaxVersion: 4.0
@@ -622,7 +644,7 @@ OData-Version: 4.0
622644
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
623645
624646
{
625-
"@odata.context":"[Organization URI]/api/data/v9.1/$metadata#accounts(name,donotpostalmail,accountratingcode,numberofemployees,revenue)",
647+
"@odata.context":"[Organization URI]/api/data/v9.2/$metadata#accounts(name,donotpostalmail,accountratingcode,numberofemployees,revenue)",
626648
"value":[
627649
{
628650
"@odata.etag":"W/\"502170\"",
@@ -666,7 +688,7 @@ Use the `$expand` system query option in the navigation properties to control wh
666688
**Request**
667689

668690
```http
669-
GET [Organization URI]/api/data/v9.1/incidents(39dd0b31-ed8b-e511-80d2-00155d2a68d4)?$select=title,_customerid_value
691+
GET [Organization URI]/api/data/v9.2/incidents(39dd0b31-ed8b-e511-80d2-00155d2a68d4)?$select=title,_customerid_value
670692
&$expand=customerid_contact($select=fullname) HTTP/1.1
671693
Accept: application/json
672694
Content-Type: application/json; charset=utf-8
@@ -684,7 +706,7 @@ OData-Version: 4.0
684706
Preference-Applied: odata.include-annotations="*"
685707
686708
{
687-
"@odata.context":"[Organization URI]/api/data/v9.1/$metadata#incidents(title,_customerid_value,customerid_contact(fullname))/$entity",
709+
"@odata.context":"[Organization URI]/api/data/v9.2/$metadata#incidents(title,_customerid_value,customerid_contact(fullname))/$entity",
688710
"@odata.etag":"W/\"504696\"",
689711
"_customerid_value@Microsoft.Dynamics.CRM.associatednavigationproperty":"customerid_contact",
690712
"[email protected]":"contact",

0 commit comments

Comments
 (0)