0.6.1-beta.2 • Published 1 year ago

@primno/d365-client v0.6.1-beta.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Dynamics 365 Client for Node.JS

npm npm

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 typeOnlineOn-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

  1. 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" }]
        }
    );
  2. Create a contact.

    const contact = await client.createRecord("contacts", {
        firstname: "Sophie", lastname: "Germain"
    });
  3. Delete a account.

    await client.deleteRecord("accounts", "00000000-0000-0000-0000-000000000000");
  4. Retrieves a contact by its id.

    const contact = await client.retrieveRecord("contacts", "00000000-0000-0000-0000-000000000000", { select: ["firstname"] });
  5. Retrieves actives opportunies using a custom query option string.

    const opportunities = await d365Client.retrieveMultipleRecords("opportunities", "?$select=name,$filter=state eq 0");
  6. 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);
  7. 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.