Skip to content

Commit 1864801

Browse files
authored
Add example for Dataverse operations in README
Added an example demonstrating basic Dataverse operations using the SDK for Python.
1 parent 75d498a commit 1864801

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,42 @@ Read our Microsoft Learn documentation to learn how to access Dataverse by using
2020
- [Customize tables and columns](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sdk-python/metadata)
2121
- [Manage table relationships](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sdk-python/relationships)
2222
- [Asynchronous client operations](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sdk-python/async-client)
23-
- [Handle errors and enable HTTP diagnostics](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sdk-python//error-handling)
23+
- [Handle errors and enable HTTP diagnostics](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sdk-python//error-handling)
24+
25+
## An example
26+
27+
Following is a short example that demonstrates some basic Dataverse operations by using the SDK for Python. Read the documentation to learn more.
28+
29+
```csharp
30+
from azure.identity import InteractiveBrowserCredential
31+
from PowerPlatform.Dataverse.client import DataverseClient
32+
33+
# Replace <myorg> with the name of a valid environment.
34+
base_url = "https://<myorg>.crm.dynamics.com"
35+
client = DataverseClient(base_url=base_url, credential=InteractiveBrowserCredential())
36+
37+
# Create a record
38+
account_id = client.records.create("account", {"name": "Contoso Ltd"})
39+
40+
# Read a record
41+
account = client.records.retrieve("account", account_id)
42+
print(account["name"])
43+
44+
# Read with expand fetches a related record in the same HTTP request
45+
account = client.records.retrieve(
46+
"account", account_id,
47+
select=["name"],
48+
expand=["primarycontactid"],
49+
)
50+
contact = (account.get("primarycontactid") or {})
51+
print(contact.get("fullname"))
52+
53+
# Update a record
54+
client.records.update("account", account_id, {"telephone1": "555-0199"})
55+
56+
# Delete a record
57+
client.records.delete("account", account_id)
58+
```
2459

2560
## Contributing
2661

0 commit comments

Comments
 (0)