-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataverse_lookup_bind.js
More file actions
33 lines (28 loc) · 877 Bytes
/
dataverse_lookup_bind.js
File metadata and controls
33 lines (28 loc) · 877 Bytes
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
const environmentUrl = "https://yourorg.crm.dynamics.com";
const accessToken = "YOUR_ACCESS_TOKEN";
const contactId = "CONTACT_GUID";
const accountId = "ACCOUNT_GUID";
const headers = {
Authorization: `Bearer ${accessToken}`,
Accept: "application/json",
"Content-Type": "application/json",
"OData-Version": "4.0",
"OData-MaxVersion": "4.0",
};
async function run() {
const response = await fetch(`${environmentUrl}/api/data/v9.2/contacts(${contactId})`, {
method: "PATCH",
headers,
body: JSON.stringify({
"parentcustomerid_account@odata.bind": `/accounts(${accountId})`,
}),
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
console.log(`Linked contact ${contactId} to account ${accountId}`);
}
run().catch((error) => {
console.error(error);
process.exitCode = 1;
});