-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataverse_create_update_delete.py
More file actions
44 lines (38 loc) · 1.16 KB
/
dataverse_create_update_delete.py
File metadata and controls
44 lines (38 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
ENVIRONMENT_URL = "https://yourorg.crm.dynamics.com"
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Accept": "application/json",
"Content-Type": "application/json",
"OData-Version": "4.0",
"OData-MaxVersion": "4.0",
}
create_response = requests.post(
f"{ENVIRONMENT_URL}/api/data/v9.2/accounts",
headers=headers,
json={
"name": "Contoso Example Account",
"telephone1": "03 9000 0000",
},
timeout=30,
)
create_response.raise_for_status()
entity_id_header = create_response.headers.get("OData-EntityId", "")
account_id = entity_id_header.split("(")[-1].rstrip(")")
print(f"Created account: {account_id}")
update_response = requests.patch(
f"{ENVIRONMENT_URL}/api/data/v9.2/accounts({account_id})",
headers=headers,
json={"telephone1": "03 9555 1234"},
timeout=30,
)
update_response.raise_for_status()
print(f"Updated account: {account_id}")
delete_response = requests.delete(
f"{ENVIRONMENT_URL}/api/data/v9.2/accounts({account_id})",
headers=headers,
timeout=30,
)
delete_response.raise_for_status()
print(f"Deleted account: {account_id}")