-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataverse_lookup_bind.cs
More file actions
34 lines (29 loc) · 1.24 KB
/
dataverse_lookup_bind.cs
File metadata and controls
34 lines (29 loc) · 1.24 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
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
public class DataverseLookupBindExample
{
public static async Task Main()
{
var environmentUrl = "https://yourorg.crm.dynamics.com";
var accessToken = "YOUR_ACCESS_TOKEN";
var contactId = "CONTACT_GUID";
var accountId = "ACCOUNT_GUID";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("OData-Version", "4.0");
client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
var payload = $$"""
{
"parentcustomerid_account@odata.bind": "/accounts({{accountId}})"
}
""";
using var content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = await client.PatchAsync(environmentUrl + $"/api/data/v9.2/contacts({contactId})", content);
response.EnsureSuccessStatusCode();
Console.WriteLine($"Linked contact {contactId} to account {accountId}");
}
}