Skip to content

Commit d76321f

Browse files
committed
sample code added
1 parent 30c2817 commit d76321f

File tree

1 file changed

+131
-13
lines changed

1 file changed

+131
-13
lines changed

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

Lines changed: 131 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Column Names in Web API are all lower case using the <xref:Microsoft.Xrm.Sdk.Met
6767

6868
### HTTP methods
6969

70-
Organization Data Service uses `MERGE` or `PUT` rather than `PATCH`.
70+
Organization Data Service uses `MERGE` or `PUT` rather than `PATCH` to update a record.
7171

7272
### Data format
7373

@@ -278,7 +278,7 @@ Preference-Applied: odata.maxpagesize=2
278278

279279
### Create records
280280

281-
These examples show the differences between the Organization Data Service and the Web API when creating records.
281+
These examples show the differences between the Organization Data Service and the Web API when creating records.
282282

283283
#### [Organization Data Service](#tab/odatav2)
284284

@@ -335,6 +335,8 @@ REQ_ID: a0c614be-50be-4c1e-9413-1c7ba459c5c9
335335

336336
#### [Web API](#tab/webapi)
337337

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`.
339+
338340
**Request**
339341

340342
```http
@@ -408,13 +410,50 @@ These examples show the differences between the Organization Data Service and th
408410
**Request**
409411

410412
```http
411-
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
414+
Accept: application/json
412415
```
413416

414417
**Response**
415418

416419
```http
420+
HTTP/1.1 200 OK
417421
422+
{
423+
"d": {
424+
"__metadata": {
425+
"uri": "https://crmue.api.crm.dynamics.com/xrmservices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e')",
426+
"type": "Microsoft.Crm.Sdk.Data.Services.Account"
427+
},
428+
"OwnershipCode": {
429+
"__metadata": {
430+
"type": "Microsoft.Crm.Sdk.Data.Services.OptionSetValue"
431+
},
432+
"Value": 2
433+
},
434+
"PrimaryContactId": {
435+
"__metadata": {
436+
"type": "Microsoft.Crm.Sdk.Data.Services.EntityReference"
437+
},
438+
"Id": "dff27d1f-a61b-4bfe-a203-b2e5a36cda0e",
439+
"LogicalName": "contact",
440+
"Name": "Sam Smith",
441+
"RowVersion": null
442+
},
443+
"OpenDeals_Date": "/Date(1663784098000)/",
444+
"Telephone1": "555-1234",
445+
"NumberOfEmployees": 500,
446+
"Name": "Contoso, Ltd. (sample)",
447+
"AccountNumber": "12227",
448+
"DoNotPhone": true,
449+
"IndustryCode": {
450+
"__metadata": {
451+
"type": "Microsoft.Crm.Sdk.Data.Services.OptionSetValue"
452+
},
453+
"Value": 7
454+
}
455+
}
456+
}
418457
419458
```
420459

@@ -423,13 +462,48 @@ These examples show the differences between the Organization Data Service and th
423462
**Request**
424463

425464
```http
426-
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
466+
Prefer: odata.include-annotations="*"
467+
Prefer: return=representation
468+
OData-MaxVersion: 4.0
469+
OData-Version: 4.0
470+
If-None-Match: null
471+
Accept: application/json
427472
```
428473

429474
**Response**
430475

431476
```http
477+
HTTP/1.1 200 OK
478+
Content-Type: application/json; odata.metadata=minimal
479+
ETag: W/"73921464"
480+
OData-Version: 4.0
481+
Preference-Applied: odata.include-annotations="*"
432482
483+
{
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",
485+
"@odata.etag": "W/\"73921464\"",
486+
"[email protected]": "Private",
487+
"ownershipcode": 2,
488+
"_primarycontactid_value@OData.Community.Display.V1.FormattedValue": "Sam Smith",
489+
"_primarycontactid_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "primarycontactid",
490+
"[email protected]": "contact",
491+
"_primarycontactid_value": "dff27d1f-a61b-4bfe-a203-b2e5a36cda0e",
492+
"[email protected]": "9/21/2022 11:14 AM",
493+
"opendeals_date": "2022-09-21T18:14:58Z",
494+
"[email protected]": "Default Value",
495+
"customersizecode": 1,
496+
"telephone1": "555-1234",
497+
498+
"numberofemployees": 500,
499+
"name": "Contoso, Ltd. (sample)",
500+
"accountnumber": "12227",
501+
"[email protected]": "Do Not Allow",
502+
"donotphone": true,
503+
"[email protected]": "Consulting",
504+
"industrycode": 7,
505+
"accountid": "b68d56a6-4739-ed11-9db0-002248296d7e"
506+
}
433507
434508
```
435509

@@ -444,13 +518,34 @@ These examples show the differences between the Organization Data Service and th
444518
**Request**
445519

446520
```http
521+
POST https://crmue.api.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e') HTTP/1.1
522+
Accept: application/json
523+
X-HTTP-Method: MERGE
524+
Content-Type: application/json
447525
526+
{
527+
"OwnershipCode": {
528+
"Value": 3
529+
},
530+
"PrimaryContactId": {
531+
"Id": "6db0be2e-d01c-ed11-b83e-000d3a572421"
532+
},
533+
"OpenDeals_Date": "12/26/2022",
534+
"Telephone1": "555-1235",
535+
"NumberOfEmployees": 501,
536+
"Name": "Contoso, Ltd.",
537+
"AccountNumber": "12228",
538+
"DoNotPhone": false,
539+
"IndustryCode": {
540+
"Value": 6
541+
}
542+
}
448543
```
449544

450545
**Response**
451546

452547
```http
453-
548+
HTTP/1.1 204 No Content
454549
455550
```
456551

@@ -459,14 +554,33 @@ These examples show the differences between the Organization Data Service and th
459554
**Request**
460555

461556
```http
557+
PATCH https://crmue.api.crm.dynamics.com/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e) HTTP/1.1
558+
OData-MaxVersion: 4.0
559+
OData-Version: 4.0
560+
If-None-Match: null
561+
Accept: application/json
562+
Content-Type: application/json
563+
564+
{
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
574+
}
462575
463576
```
464577

465578
**Response**
466579

467580
```http
468-
469-
581+
HTTP/1.1 204 No Content
582+
OData-Version: 4.0
583+
OData-EntityId: https://crmue.api.crm.dynamics.com/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e)
470584
```
471585

472586
---
@@ -480,29 +594,33 @@ These examples show the differences between the Organization Data Service and th
480594
**Request**
481595

482596
```http
483-
597+
DELETE https://crmue.api.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/AccountSet(guid'b68d56a6-4739-ed11-9db0-002248296d7e') HTTP/1.1
598+
Accept: application/json
484599
```
485600

486601
**Response**
487602

488603
```http
489-
490-
604+
HTTP/1.1 204 No Content
491605
```
492606

493607
#### [Web API](#tab/webapi)
494608

495609
**Request**
496610

497611
```http
498-
612+
DELETE https://crmue.api.crm.dynamics.com/api/data/v9.2/accounts(b68d56a6-4739-ed11-9db0-002248296d7e) HTTP/1.1
613+
OData-MaxVersion: 4.0
614+
OData-Version: 4.0
615+
If-None-Match: null
616+
Accept: application/json
499617
```
500618

501619
**Response**
502620

503621
```http
504-
505-
622+
HTTP/1.1 204 No Content
623+
OData-Version: 4.0
506624
```
507625

508626
---

0 commit comments

Comments
 (0)