Skip to content

Commit f4590e7

Browse files
committed
Done?
1 parent d76321f commit f4590e7

File tree

1 file changed

+50
-21
lines changed

1 file changed

+50
-21
lines changed

powerapps-docs/developer/model-driven-apps/best-practices/business-logic/do-not-use-odata-v2-endpoint.md

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,16 @@ The following table connects related areas for the Organization Data Service and
102102

103103
This section highlights the differences between using the Organization Data Service and the Web API.
104104

105+
The Organization Data Service is only able to perform Create, Retrieve, Update, and Delete operations on tables. These examples show the differences between the services to help migrate to the Web API.
106+
105107
### Query records
106108

107109
These examples show the differences between the Organization Data Service and the Web API when querying records.
108110

109111
#### [Organization Data Service](#tab/odatav2)
110112

113+
The Organization Data Service has no way to manage paging other than using `$top `and `$skip`, but the maximum page size was limited to 50 records.
114+
111115
**Request**
112116

113117
```http
@@ -197,8 +201,16 @@ Content-Type: application/json;charset=utf-8
197201
}
198202
```
199203

204+
When more than 50 records were returned, there is a `__next` property to access the next page:
205+
206+
```json
207+
"__next": "https://[Organization URI]/XRMServices/2011/OrganizationData.svc/AccountSet?$select=OwnershipCode,PrimaryContactId,OpenDeals_Date,Telephone1,NumberOfEmployees,Name,AccountNumber,DoNotPhone,IndustryCode&$filter=PrimaryContactId/Id ne null&$skiptoken=1,'accountid','%7B22153355-851D-ED11-B83E-000D3A572421%7D','%7B7A4814F9-B0B8-EA11-A812-000D3A122B89%7D'"
208+
```
209+
200210
#### [Web API](#tab/webapi)
201211

212+
With Web API you have explicit control over paging using the `Prefer: odata.maxpagesize` request header.
213+
202214
**Request**
203215

204216
```http
@@ -270,6 +282,7 @@ Preference-Applied: odata.maxpagesize=2
270282
"@odata.nextLink": " [Organization URI]/api/data/v9.2/accounts?$select=ownershipcode,_primarycontactid_value,opendeals_date,telephone1,numberofemployees,name,accountnumber,donotphone,industrycode&$filter=_primarycontactid_value%20ne%20null&$count=true&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%253e%253caccountid%2520last%253d%2522%257bFED58509-4AF3-EC11-BB3D-000D3A1A51C1%257d%2522%2520first%253d%2522%257b7A4814F9-B0B8-EA11-A812-000D3A122B89%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E"
271283
}
272284
285+
A Url for the next page is available using the `@odata.nextLink` property.
273286
274287
```
275288

@@ -315,6 +328,8 @@ Content-Type: application/json
315328

316329
**Response**
317330

331+
With the Organization Data Service all properties are returned when a record is created.
332+
318333
```http
319334
HTTP/1.1 201 Created
320335
Content-Type: application/json;charset=utf-8
@@ -327,15 +342,17 @@ REQ_ID: a0c614be-50be-4c1e-9413-1c7ba459c5c9
327342
"type": "Microsoft.Crm.Sdk.Data.Services.Account"
328343
},
329344
"AccountId": "57d4d1af-7b38-ed11-9db0-002248296d7e",
330-
<All properties are returned>
345+
346+
<All properties are returned. Removed for brevity>
347+
331348
}
332349
}
333350
334351
```
335352

336353
#### [Web API](#tab/webapi)
337354

338-
The Web API example in this case uses the `Prefer: return=representation` request header which defines a behavior similar to the Organization Data Service behavior of returning `201 Created` with the columns defined by the `$select` query option. Without this request header, Web API returns `201 No Content`.
355+
The Web API example in this case uses the `Prefer: return=representation` request header which defines a behavior similar to the Organization Data Service behavior of returning `201 Created` with the columns defined by the `$select` query option. Without this request header, Web API returns `201 No Content` and the id of the record created is included in the url value of the `OData-EntityId` reponse header.
339356

340357
**Request**
341358

@@ -399,6 +416,17 @@ Preference-Applied: odata.include-annotations="*"
399416
400417
```
401418

419+
Or without `Prefer: return=representation`, the response will be like this:
420+
421+
**Response**
422+
423+
```http
424+
HTTP/1.1 204 No Content
425+
Content-Type: application/json; odata.metadata=minimal
426+
OData-Version: 4.0
427+
OData-EntityId: https://[Organization URI]/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e)
428+
```
429+
402430
---
403431

404432
### Retrieve records
@@ -410,7 +438,7 @@ These examples show the differences between the Organization Data Service and th
410438
**Request**
411439

412440
```http
413-
GET https://crmue.api.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e')?$select=OwnershipCode,PrimaryContactId,OpenDeals_Date,Telephone1,NumberOfEmployees,Name,AccountNumber,DoNotPhone,IndustryCode HTTP/1.1
441+
GET https://[Organization URI]/XRMServices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e')?$select=OwnershipCode,PrimaryContactId,OpenDeals_Date,Telephone1,NumberOfEmployees,Name,AccountNumber,DoNotPhone,IndustryCode HTTP/1.1
414442
Accept: application/json
415443
```
416444

@@ -422,7 +450,7 @@ HTTP/1.1 200 OK
422450
{
423451
"d": {
424452
"__metadata": {
425-
"uri": "https://crmue.api.crm.dynamics.com/xrmservices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e')",
453+
"uri": "https://[Organization URI]/xrmservices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e')",
426454
"type": "Microsoft.Crm.Sdk.Data.Services.Account"
427455
},
428456
"OwnershipCode": {
@@ -462,9 +490,8 @@ HTTP/1.1 200 OK
462490
**Request**
463491

464492
```http
465-
GET https://crmue.api.crm.dynamics.com/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e)?$select=ownershipcode,_primarycontactid_value,opendeals_date,customersizecode,telephone1,numberofemployees,name,accountnumber,donotphone,industrycode HTTP/1.1
493+
GET https://[Organization URI]/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e)?$select=ownershipcode,_primarycontactid_value,opendeals_date,customersizecode,telephone1,numberofemployees,name,accountnumber,donotphone,industrycode HTTP/1.1
466494
Prefer: odata.include-annotations="*"
467-
Prefer: return=representation
468495
OData-MaxVersion: 4.0
469496
OData-Version: 4.0
470497
If-None-Match: null
@@ -481,7 +508,7 @@ OData-Version: 4.0
481508
Preference-Applied: odata.include-annotations="*"
482509
483510
{
484-
"@odata.context": "https://crmue.api.crm.dynamics.com/api/data/v9.2/$metadata#accounts(ownershipcode,_primarycontactid_value,opendeals_date,customersizecode,telephone1,numberofemployees,name,accountnumber,donotphone,industrycode)/$entity",
511+
"@odata.context": "https://[Organization URI]/api/data/v9.2/$metadata#accounts(ownershipcode,_primarycontactid_value,opendeals_date,customersizecode,telephone1,numberofemployees,name,accountnumber,donotphone,industrycode)/$entity",
485512
"@odata.etag": "W/\"73921464\"",
486513
"[email protected]": "Private",
487514
"ownershipcode": 2,
@@ -515,10 +542,12 @@ These examples show the differences between the Organization Data Service and th
515542

516543
#### [Organization Data Service](#tab/odatav2)
517544

545+
Organization Data Service requires the `X-HTTP-Method: MERGE` request header to be applied with a `POST` request.
546+
518547
**Request**
519548

520549
```http
521-
POST https://crmue.api.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e') HTTP/1.1
550+
POST https://[Organization URI]/XRMServices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e') HTTP/1.1
522551
Accept: application/json
523552
X-HTTP-Method: MERGE
524553
Content-Type: application/json
@@ -554,23 +583,23 @@ HTTP/1.1 204 No Content
554583
**Request**
555584

556585
```http
557-
PATCH https://crmue.api.crm.dynamics.com/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e) HTTP/1.1
586+
PATCH https://[Organization URI]/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e) HTTP/1.1
558587
OData-MaxVersion: 4.0
559588
OData-Version: 4.0
560589
If-None-Match: null
561590
Accept: application/json
562591
Content-Type: application/json
563592
564593
{
565-
"ownershipcode": 3,
566-
"[email protected]":"/contacts(6db0be2e-d01c-ed11-b83e-000d3a572421)",
567-
"opendeals_date": "2022-12-26T00:00:00Z",
568-
"telephone1":"555-1235",
569-
"numberofemployees": 501,
570-
"name":"Contoso, Ltd.",
571-
"accountnumber": "12229",
572-
"donotphone": false,
573-
"industrycode": 6
594+
"ownershipcode": 3,
595+
"[email protected]": "/contacts(6db0be2e-d01c-ed11-b83e-000d3a572421)",
596+
"opendeals_date": "2022-12-26T00:00:00Z",
597+
"telephone1": "555-1235",
598+
"numberofemployees": 501,
599+
"name": "Contoso, Ltd.",
600+
"accountnumber": "12229",
601+
"donotphone": false,
602+
"industrycode": 6
574603
}
575604
576605
```
@@ -580,7 +609,7 @@ Content-Type: application/json
580609
```http
581610
HTTP/1.1 204 No Content
582611
OData-Version: 4.0
583-
OData-EntityId: https://crmue.api.crm.dynamics.com/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e)
612+
OData-EntityId: https://[Organization URI]/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e)
584613
```
585614

586615
---
@@ -594,7 +623,7 @@ These examples show the differences between the Organization Data Service and th
594623
**Request**
595624

596625
```http
597-
DELETE https://crmue.api.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e') HTTP/1.1
626+
DELETE https://[Organization URI]/XRMServices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e') HTTP/1.1
598627
Accept: application/json
599628
```
600629

@@ -609,7 +638,7 @@ HTTP/1.1 204 No Content
609638
**Request**
610639

611640
```http
612-
DELETE https://crmue.api.crm.dynamics.com/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e) HTTP/1.1
641+
DELETE https://[Organization URI]/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e) HTTP/1.1
613642
OData-MaxVersion: 4.0
614643
OData-Version: 4.0
615644
If-None-Match: null

0 commit comments

Comments
 (0)