@primno/d365-client v0.6.1-beta.2
Dynamics 365 Client for Node.JS
d365-client is a library written in Typescript that allows you to make requests to the Dynamics 365 / Dataverse APIs in Node.JS.
Dynamics 365 CE (on-premises) and Dynamics 365 Online are supported.
Dynamics 365 CE (on-premises) is supported since version 9.0 with CBA/IFD deployment (ADFS 2019+ only with OAuth enabled).
Important d365-client is in beta stage and subject to change.
Installation
npm install @primno/d365-client
Authentication
d365-client works with historical connection strings (see D365 online doc and D365 CE on-premises doc).
Persistence token cache is supported for Dynamics 365 Online.
Supported authentication type
Auth type | Online | On-premises |
---|---|---|
OAuth | :heavy_check_mark: | :heavy_check_mark: |
AD | :x: | :heavy_check_mark: |
Certificate | :x: | :x: |
Examples :
Dynamics 365 Online : AuthType=OAuth;Url=https://<Environnement>.crm.dynamics.com;UserName=<UserName>;Password=<Password>
Dynamics 365 CE (on-premise) OAuth : AuthType=OAuth;RedirectUri=<RedirectUri>;ClientSecret=<ClientSecret>;Url=https://<D365Url>;UserName=<Domain>\<UserName>;Password=<Password>
Dynamics 365 CE (on-premise) AD (NTLM authentication): AuthType=AD;Url=https://<D365Url>;UserName=<AdUserName>;Domain=<Domain>;Password=<Password>
Queries
CRUD and execute operations are supported.
Examples
Retrieves first 10 accounts.
import { D365Client } from '@primno/d365-client'; interface Account { name: string; emailaddress1: string; } const connectionString = '...'; const d365Client = new D365Client(connectionString); const accounts = await d365Client.retrieveMultipleRecords<Account>( "accounts", { top: 10, select: ["name", "emailaddress1"], orders: [{ attribute: "name", order: "asc" }] } );
Create a contact.
const contact = await client.createRecord("contacts", { firstname: "Sophie", lastname: "Germain" });
Delete a account.
await client.deleteRecord("accounts", "00000000-0000-0000-0000-000000000000");
Retrieves a contact by its id.
const contact = await client.retrieveRecord("contacts", "00000000-0000-0000-0000-000000000000", { select: ["firstname"] });
Retrieves actives opportunies using a custom query option string.
const opportunities = await d365Client.retrieveMultipleRecords("opportunities", "?$select=name,$filter=state eq 0");
Retrieves all contacts using OData pagination. The page size is set to 50. The nextLink attribute is used to get the next page.
const contacts = []; // Will contain all contacts. let options: RetrieveMultipleOptions | undefined = { select: ["firstname", "lastname"] }; let result: EntityCollection; do { result = await client.retrieveMultipleRecords("contacts", options, 50 /* Page Size = 50 */); contacts.push(...result.entities); options = result.nextLink; } while(result.nextLink); console.log(contacts);
Retrieves contacts created this month.
const contacts = await client.retrieveMultipleRecords("accounts", { select: ["name"], filters: [{ conditions: [{ attribute: "createdon", operator: "ThisMonth" }] }] });
Credits
Thanks to HSO for query options.
Thanks to Microsoft for persistence cache.
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago