Skip to content

Commit 633b9c2

Browse files
Samson Gebreclaude
andcommitted
docs: add upsert usage to README and SKILL.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4854b37 commit 633b9c2

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

.claude/skills/dataverse-sdk-use/SKILL.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,39 @@ client.records.update("account", account_id, {"telephone1": "555-0200"})
107107
client.records.update("account", [id1, id2, id3], {"industry": "Technology"})
108108
```
109109

110+
#### Upsert Records
111+
Creates or updates records identified by alternate keys. Single item → PATCH; multiple items → `UpsertMultiple` bulk action.
112+
```python
113+
from PowerPlatform.Dataverse.models.upsert import UpsertItem
114+
115+
# Single upsert
116+
client.records.upsert("account", [
117+
UpsertItem(
118+
alternate_key={"accountnumber": "ACC-001"},
119+
record={"name": "Contoso Ltd", "telephone1": "555-0100"},
120+
)
121+
])
122+
123+
# Bulk upsert (uses UpsertMultiple API automatically)
124+
client.records.upsert("account", [
125+
UpsertItem(alternate_key={"accountnumber": "ACC-001"}, record={"name": "Contoso Ltd"}),
126+
UpsertItem(alternate_key={"accountnumber": "ACC-002"}, record={"name": "Fabrikam Inc"}),
127+
])
128+
129+
# Composite alternate key
130+
client.records.upsert("account", [
131+
UpsertItem(
132+
alternate_key={"accountnumber": "ACC-001", "address1_postalcode": "98052"},
133+
record={"name": "Contoso Ltd"},
134+
)
135+
])
136+
137+
# Plain dict syntax (no import needed)
138+
client.records.upsert("account", [
139+
{"alternate_key": {"accountnumber": "ACC-001"}, "record": {"name": "Contoso Ltd"}}
140+
])
141+
```
142+
110143
#### Delete Records
111144
```python
112145
# Single delete

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ A Python client library for Microsoft Dataverse that provides a unified interfac
2323
- [Quick start](#quick-start)
2424
- [Basic CRUD operations](#basic-crud-operations)
2525
- [Bulk operations](#bulk-operations)
26+
- [Upsert operations](#upsert-operations)
2627
- [Query data](#query-data)
2728
- [Table management](#table-management)
2829
- [Relationship management](#relationship-management)
@@ -34,7 +35,7 @@ A Python client library for Microsoft Dataverse that provides a unified interfac
3435
## Key features
3536

3637
- **🔄 CRUD Operations**: Create, read, update, and delete records with support for bulk operations and automatic retry
37-
- **⚡ True Bulk Operations**: Automatically uses Dataverse's native `CreateMultiple`, `UpdateMultiple`, and `BulkDelete` Web API operations for maximum performance and transactional integrity
38+
- **⚡ True Bulk Operations**: Automatically uses Dataverse's native `CreateMultiple`, `UpdateMultiple`, `UpsertMultiple`, and `BulkDelete` Web API operations for maximum performance and transactional integrity
3839
- **📊 SQL Queries**: Execute read-only SQL queries via the Dataverse Web API `?sql=` parameter
3940
- **🏗️ Table Management**: Create, inspect, and delete custom tables and columns programmatically
4041
- **🔗 Relationship Management**: Create one-to-many and many-to-many relationships between tables with full metadata control
@@ -178,6 +179,52 @@ client.records.update("account", ids, {"industry": "Technology"})
178179
client.records.delete("account", ids, use_bulk_delete=True)
179180
```
180181

182+
### Upsert operations
183+
184+
Use `client.records.upsert()` to create or update records identified by alternate keys. When the
185+
key matches an existing record it is updated; otherwise the record is created. A single item uses
186+
a PATCH request; multiple items use the `UpsertMultiple` bulk action.
187+
188+
```python
189+
from PowerPlatform.Dataverse.models.upsert import UpsertItem
190+
191+
# Upsert a single record
192+
client.records.upsert("account", [
193+
UpsertItem(
194+
alternate_key={"accountnumber": "ACC-001"},
195+
record={"name": "Contoso Ltd", "telephone1": "555-0100"},
196+
)
197+
])
198+
199+
# Upsert multiple records (uses UpsertMultiple bulk action)
200+
client.records.upsert("account", [
201+
UpsertItem(
202+
alternate_key={"accountnumber": "ACC-001"},
203+
record={"name": "Contoso Ltd"},
204+
),
205+
UpsertItem(
206+
alternate_key={"accountnumber": "ACC-002"},
207+
record={"name": "Fabrikam Inc"},
208+
),
209+
])
210+
211+
# Composite alternate key (multiple columns identify the record)
212+
client.records.upsert("account", [
213+
UpsertItem(
214+
alternate_key={"accountnumber": "ACC-001", "address1_postalcode": "98052"},
215+
record={"name": "Contoso Ltd"},
216+
)
217+
])
218+
219+
# Plain dict syntax (no import needed)
220+
client.records.upsert("account", [
221+
{
222+
"alternate_key": {"accountnumber": "ACC-001"},
223+
"record": {"name": "Contoso Ltd"},
224+
}
225+
])
226+
```
227+
181228
### Query data
182229

183230
```python

src/PowerPlatform/Dataverse/claude_skill/dataverse-sdk-use/SKILL.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,39 @@ client.records.update("account", account_id, {"telephone1": "555-0200"})
107107
client.records.update("account", [id1, id2, id3], {"industry": "Technology"})
108108
```
109109

110+
#### Upsert Records
111+
Creates or updates records identified by alternate keys. Single item → PATCH; multiple items → `UpsertMultiple` bulk action.
112+
```python
113+
from PowerPlatform.Dataverse.models.upsert import UpsertItem
114+
115+
# Single upsert
116+
client.records.upsert("account", [
117+
UpsertItem(
118+
alternate_key={"accountnumber": "ACC-001"},
119+
record={"name": "Contoso Ltd", "telephone1": "555-0100"},
120+
)
121+
])
122+
123+
# Bulk upsert (uses UpsertMultiple API automatically)
124+
client.records.upsert("account", [
125+
UpsertItem(alternate_key={"accountnumber": "ACC-001"}, record={"name": "Contoso Ltd"}),
126+
UpsertItem(alternate_key={"accountnumber": "ACC-002"}, record={"name": "Fabrikam Inc"}),
127+
])
128+
129+
# Composite alternate key
130+
client.records.upsert("account", [
131+
UpsertItem(
132+
alternate_key={"accountnumber": "ACC-001", "address1_postalcode": "98052"},
133+
record={"name": "Contoso Ltd"},
134+
)
135+
])
136+
137+
# Plain dict syntax (no import needed)
138+
client.records.upsert("account", [
139+
{"alternate_key": {"accountnumber": "ACC-001"}, "record": {"name": "Contoso Ltd"}}
140+
])
141+
```
142+
110143
#### Delete Records
111144
```python
112145
# Single delete

0 commit comments

Comments
 (0)