Comprehensive JavaScript framework for Microsoft Dynamics CRM/365 WebAPI integration with promise-based CRUD operations, batch processing, and 200+ pre-implemented actions
npx @tessl/cli install tessl/npm-xrm-webapi-client@4.1.0XRM WebAPI Client is a comprehensive JavaScript framework for working with Microsoft Dynamics CRM/365 Web API. It provides both synchronous and asynchronous operations through promise-based architecture using Bluebird, supporting complete CRUD operations, advanced querying with FetchXML and OData, batch processing, and 200+ pre-implemented CRM actions.
npm install xrm-webapi-clientimport * as WebApiClient from "xrm-webapi-client";For CommonJS:
const WebApiClient = require("xrm-webapi-client");import * as WebApiClient from "xrm-webapi-client";
// Configure the client
WebApiClient.ApiVersion = "9.0";
WebApiClient.ReturnAllPages = true;
WebApiClient.PrettifyErrors = false;
// Create a record
const accountId = await WebApiClient.Create({
entityName: "account",
entity: {
name: "Contoso Corporation",
telephone1: "555-0123",
websiteurl: "https://contoso.com"
}
});
// Retrieve a record
const account = await WebApiClient.Retrieve({
entityName: "account",
entityId: accountId,
queryParams: "?$select=name,telephone1,websiteurl"
});
// Update a record
await WebApiClient.Update({
entityName: "account",
entityId: accountId,
entity: { telephone1: "555-9999" }
});
// Delete a record
await WebApiClient.Delete({
entityName: "account",
entityId: accountId
});XRM WebAPI Client is built around several key components:
Core create, retrieve, update, and delete operations for CRM entities with support for alternate keys, query parameters, and FetchXML.
function Create(parameters: CreateParameters): Promise<string> | Promise<any> | string | any | BatchRequest;
function Retrieve(parameters: RetrieveParameters): Promise<any> | any | BatchRequest;
function Update(parameters: UpdateParameters): Promise<string> | Promise<any> | string | any | BatchRequest;
function Delete(parameters: DeleteParameters): Promise<string> | string | BatchRequest;
interface CreateParameters extends BaseParameters {
entityName?: string;
overriddenSetName?: string;
entity: object;
}
interface RetrieveParameters extends BaseParameters {
entityName?: string;
overriddenSetName?: string;
entityId?: string;
alternateKey?: Array<Key>;
queryParams?: string;
fetchXml?: string;
returnAllPages?: boolean;
}
interface UpdateParameters extends BaseParameters {
entityName?: string;
overriddenSetName?: string;
entityId?: string;
entity: object;
alternateKey?: Array<Key>;
}
interface DeleteParameters extends BaseParameters {
entityName?: string;
overriddenSetName?: string;
entityId?: string;
alternateKey?: Array<Key>;
}Associate and disassociate operations for managing relationships between CRM entities.
function Associate(parameters: AssociationParameters): Promise<string> | string | BatchRequest;
function Disassociate(parameters: AssociationParameters): Promise<string> | string | BatchRequest;
interface AssociationParameters extends BaseParameters {
relationShip: string;
source: EntityReference;
target: EntityReference;
}
interface EntityReference {
entityName: string;
entityId: string;
}Transaction-based batch operations allowing multiple requests to be sent together with rollback capabilities.
function SendBatch(batch: Batch): Promise<BatchResponse> | BatchResponse;
class Batch implements BatchParameters {
name?: string;
changeSets?: Array<ChangeSet>;
requests?: Array<BatchRequest>;
headers?: Array<Header>;
async?: boolean;
isOverLengthGet?: boolean;
constructor(parameters: BatchParameters);
}
class BatchResponse implements BatchResponseParameters {
name?: string;
changeSetResponses?: Array<ChangeSetResponse>;
batchResponses?: Array<Response>;
isFaulted?: boolean;
errors?: Array<string>;
xhr?: XMLHttpRequest;
constructor(parameters: BatchResponseParameters);
}Execute pre-implemented CRM actions and functions, or create custom request objects.
function Execute(request: object): Promise<any> | any | BatchRequest;
namespace Requests {
class Request implements RequestParameters {
method?: string;
name?: string;
bound?: boolean;
entityName?: string;
entityId?: string;
payload?: object;
headers?: Array<Header>;
urlParams?: object;
async?: boolean;
with(param: RequestParameters): this;
}
}Client configuration, URL building, header management, and utility functions.
import * as bluebird from "bluebird";
function GetApiUrl(): string;
function GetSetName(entity: string): string;
function SendRequest(method: string, url: string, payload: object, parameters?: BaseParameters): Promise<any> | any | BatchRequest;
// Configuration Properties
let ApiVersion: string;
let ReturnAllPages: boolean;
let PrettifyErrors: boolean;
let Async: boolean;
let ClientUrl: string;
let Token: string;
let Version: string;
let Promise: typeof bluebird;interface BaseParameters {
async?: boolean;
headers?: Array<Header>;
asBatch?: boolean;
apiVersion?: string;
}
interface Header {
key: string;
value: string;
}
interface Key {
property: string;
value: string | number;
}