Skip to content

Commit 003ea1a

Browse files
authored
Merge pull request MicrosoftDocs#4455 from MicrosoftDocs/jdaly-master-web-api-disassociate
Jdaly master web api disassociate
2 parents 30158b5 + 9e0d217 commit 003ea1a

File tree

3 files changed

+86
-32
lines changed

3 files changed

+86
-32
lines changed

powerapps-docs/developer/data-platform/webapi/TOC.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
items:
3535
- name: Query data
3636
href: query-data-web-api.md
37-
- name: Retrieve related tables with query
37+
- name: Retrieve related records with query
3838
href: retrieve-related-entities-query.md
3939
- name: Retrieve and execute predefined queries
4040
href: retrieve-and-execute-predefined-queries.md
@@ -44,7 +44,7 @@
4444
href: retrieve-entity-using-web-api.md
4545
- name: Update and delete table records
4646
href: update-delete-entities-using-web-api.md
47-
- name: Associate and disassociate tables
47+
- name: Associate and disassociate records
4848
href: associate-disassociate-entities-using-web-api.md
4949
- name: Merge table records
5050
href: merge-entity-using-web-api.md

powerapps-docs/developer/data-platform/webapi/associate-disassociate-entities-using-web-api.md

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Associate and disassociate entities using the Web API (Microsoft Dataverse)| Microsoft Docs"
33
description: "Read how to add reference to a collection-valued navigation property, remove a reference and change an existing reference using the Web API"
44
ms.custom: ""
5-
ms.date: 10/31/2018
5+
ms.date: 04/3/2021
66
ms.service: powerapps
77
ms.suite: ""
88
ms.tgt_pltfrm: ""
@@ -21,6 +21,7 @@ search.app:
2121
- PowerApps
2222
- D365CE
2323
---
24+
2425
# Associate and disassociate entities using the Web API
2526

2627
[!INCLUDE[cc-data-platform-banner](../../../includes/cc-data-platform-banner.md)]
@@ -52,6 +53,36 @@ HTTP/1.1 204 No Content
5253
OData-Version: 4.0
5354
```
5455

56+
57+
58+
<a name="bkmk_Changethereferenceinasingle"></a>
59+
60+
## Change the reference in a single-valued navigation property
61+
62+
You can associate entities by setting the value of a single-valued navigation property using PUT request with the following pattern.
63+
64+
**Request**
65+
66+
```http
67+
PUT [Organization URI]/api/data/v9.0/opportunities(00000000-0000-0000-0000-000000000001)/customerid_account/$ref HTTP/1.1
68+
Content-Type: application/json
69+
Accept: application/json
70+
OData-MaxVersion: 4.0
71+
OData-Version: 4.0
72+
73+
{
74+
"@odata.id":"accounts(00000000-0000-0000-0000-000000000002)"
75+
}
76+
```
77+
78+
**Response**
79+
80+
```http
81+
HTTP/1.1 204 No Content
82+
OData-Version: 4.0
83+
```
84+
85+
5586
<a name="bkmk_Removeareferencetoanentity"></a>
5687

5788
## Remove a reference to an entity
@@ -94,45 +125,28 @@ OData-Version: 4.0
94125
HTTP/1.1 204 No Content
95126
OData-Version: 4.0
96127
```
97-
98-
<a name="bkmk_Changethereferenceinasingle"></a>
99-
100-
## Change the reference in a single-valued navigation property
101128

102-
You can associate entities by setting the value of a single-valued navigation property using PUT request with the following pattern.
103-
104-
**Request**
105129

106-
```http
107-
PUT [Organization URI]/api/data/v9.0/opportunities(00000000-0000-0000-0000-000000000001)/customerid_account/$ref HTTP/1.1
108-
Content-Type: application/json
109-
Accept: application/json
110-
OData-MaxVersion: 4.0
111-
OData-Version: 4.0
112-
113-
{
114-
"@odata.id":"[Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000002)"
115-
}
116-
```
117130

118-
**Response**
119131

120-
```http
121-
HTTP/1.1 204 No Content
122-
OData-Version: 4.0
123-
```
124132

125133
<a name="bkmk_Associateentitiesoncreate"></a>
126134

127135
## Associate entities on create
128136

129-
As described in [Create related entities in one operation](create-entity-web-api.md#bkmk_CreateRelated), new entities can be created with relationships using *deep insert*.
137+
As described in [Associate entity records on create](create-entity-web-api.md#associate-entity-records-on-create), you can associate the new record to existing records by setting the navigation properties using the `@odata.bind` annotation.
138+
139+
As described in [Create related entities in one operation](create-entity-web-api.md#bkmk_CreateRelated), new entities can be created with relationships using *deep insert*.
130140

141+
## Associate and disassociate entities on update
142+
143+
You can set the value of single-valued navigation properties using `PATCH` to associate or disassociate records.
144+
131145
<a name="bkmk_Associateentitiesonupdate"></a>
132146

133-
## Associate entities on update using single-valued navigation property
147+
### Associate entities on update
134148

135-
You can associate entities on update using the same message described in [Basic update](update-delete-entities-using-web-api.md#bkmk_update) but you must use the @odata.bind annotation to set the value of a single-valued navigation property. The following example changes the account associated to an opportunity using the `customerid_account` single-valued navigation property.
149+
You can associate entities on update using the same message described in [Basic update](update-delete-entities-using-web-api.md#bkmk_update) but you must use the `@odata.bind` annotation to set the value of a single-valued navigation property. The following example changes the account associated to an opportunity using the `customerid_account` single-valued navigation property.
136150

137151
**Request**
138152

@@ -144,7 +158,7 @@ OData-MaxVersion: 4.0
144158
OData-Version: 4.0
145159
146160
{
147-
"[email protected]":"[Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000002)"
161+
"[email protected]":"accounts(00000000-0000-0000-0000-000000000002)"
148162
}
149163
```
150164

@@ -154,6 +168,45 @@ OData-Version: 4.0
154168
HTTP/1.1 204 No Content
155169
OData-Version: 4.0
156170
```
171+
172+
### Disassociate entities on update
173+
174+
You can remove a reference to a single-valued navigation property when updating by setting the value to `null`. This method allows you to disassociate multiple references in a single operation.
175+
There are two ways to do this:
176+
177+
You can set the value to `null` using the `@odata.bind` annotation:
178+
179+
```http
180+
PATCH [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001) HTTP/1.1
181+
Accept: application/json
182+
OData-MaxVersion: 4.0
183+
OData-Version: 4.0
184+
185+
{
186+
187+
188+
}
189+
190+
191+
```
192+
193+
Or, just use the name of the single-valued navigation property.
194+
195+
```http
196+
PATCH [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001) HTTP/1.1
197+
Accept: application/json
198+
OData-MaxVersion: 4.0
199+
OData-Version: 4.0
200+
201+
{
202+
"parentaccountid": null,
203+
"primarycontactid": null
204+
}
205+
206+
```
207+
208+
More information: [Basic update](update-delete-entities-using-web-api.md#basic-update)
209+
157210
<a name="bkmk_Associateentitiesonupdate_multi"></a>
158211

159212
## Associate entities on update using collection-valued navigation property

powerapps-docs/developer/data-platform/webapi/update-delete-entities-using-web-api.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Update and delete entities using the Web API (Microsoft Dataverse)| Microsoft Docs"
33
description: "Read how to perform update and delete operations on entities using the Web API"
44
ms.custom: ""
5-
ms.date: 02/16/2021
5+
ms.date: 04/30/2021
66
ms.service: powerapps
77
ms.suite: ""
88
ms.tgt_pltfrm: ""
@@ -21,6 +21,7 @@ search.app:
2121
- PowerApps
2222
- D365CE
2323
---
24+
2425
# Update and delete entities using the Web API
2526

2627
[!INCLUDE[cc-data-platform-banner](../../../includes/cc-data-platform-banner.md)]
@@ -72,7 +73,7 @@ OData-Version: 4.0
7273
```
7374

7475
> [!NOTE]
75-
> See [Associate entities on update](associate-disassociate-entities-using-web-api.md#bkmk_Associateentitiesonupdate) for information about associating entities on update.
76+
> See [Associate and disassociate entities on update](associate-disassociate-entities-using-web-api.md#associate-and-disassociate-entities-on-update) for information about associating and disassociating entities on update.
7677
7778
<a name="bkmk_updateWithDataReturned"></a>
7879

0 commit comments

Comments
 (0)