-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataverse_create_update_delete.ps1
More file actions
30 lines (24 loc) · 1.07 KB
/
dataverse_create_update_delete.ps1
File metadata and controls
30 lines (24 loc) · 1.07 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
$environmentUrl = "https://yourorg.crm.dynamics.com"
$accessToken = "YOUR_ACCESS_TOKEN"
$headers = @{
Authorization = "Bearer $accessToken"
Accept = "application/json"
"Content-Type" = "application/json"
"OData-Version" = "4.0"
"OData-MaxVersion" = "4.0"
}
$createBody = @{
name = "Contoso Example Account"
telephone1 = "03 9000 0000"
} | ConvertTo-Json
$createResponse = Invoke-WebRequest -Method Post -Uri "$environmentUrl/api/data/v9.2/accounts" -Headers $headers -Body $createBody
$entityIdHeader = $createResponse.Headers['OData-EntityId']
$accountId = ($entityIdHeader -split '[()]')[1]
Write-Host "Created account: $accountId"
$updateBody = @{
telephone1 = "03 9555 1234"
} | ConvertTo-Json
Invoke-RestMethod -Method Patch -Uri "$environmentUrl/api/data/v9.2/accounts($accountId)" -Headers $headers -Body $updateBody | Out-Null
Write-Host "Updated account: $accountId"
Invoke-RestMethod -Method Delete -Uri "$environmentUrl/api/data/v9.2/accounts($accountId)" -Headers $headers | Out-Null
Write-Host "Deleted account: $accountId"