DynamicsWebApi is a Microsoft Dataverse Web API helper library
npm install dynamics-web-apiv2.3.0+
v2.1.0+
ts
//By default DynamicsWebApi makes calls to
//Web API v9.2 and Search API v1.0
const dynamicsWebApi = new DynamicsWebApi();
const response = await dynamicsWebApi.callFunction("WhoAmI");
Xrm.Navigation.openAlertDialog({ text: Hello Dynamics 365! My id is: ${response.UserId} });
`
$3
v.2.1.0+
There are two ways to include DynamicsWebApi in your portal: upload as a Web File or use CDN, such as unpkg.
It is possible to upload the library as a Web File in Microsoft Power Pages. Usually, the .js extensions are forbidden to upload but it is still possible to do, here's a workaround.
Once the web file is uploaded, it can be included in a template, a page or a form the following way:
`html
`
With CDN, it is a bit easier: no need to create and upload a web file - just include the script in your template, page or a form:
`html
`
And you are good to go! DynamicsWebApi will automatically detect if the library is running on Power Pages and will supply an anti-forgery token with each request.
$3
To use DynamicsWebApi in Node.js install the dynamics-web-api package from NPM:
`shell
npm install dynamics-web-api --save
`
Then include it in your script:
`ts
//CommonJS
const DynamicsWebApi = require("dynamics-web-api").DynamicsWebApi;
//ESM
import { DynamicsWebApi } from "dynamics-web-api";
`
$3
`ts
const contact = {
firstname: "John",
lastname: "Doe"
};
const order = {
name: "1 year membership",
//reference a request in a navigation property
"customerid_contact@odata.bind": "$1"
};
dynamicsWebApi.startBatch();
dynamicsWebApi.create({ data: contact, collection: "contacts", contentId: "1" });
dynamicsWebApi.create({ data: order, collection: "salesorders" });
const responses = await dynamicsWebApi.executeBatch();
//in this case both ids exist in a response
//which makes it a preferred method
const contactId = responses[0];
const salesorderId = responses[1];
`
$3
Contributions
First of all, I would like to thank you for using DynamicsWebApi library in your Dynamics 365 CE / Common Data Service project, the fact that my project helps someone to achieve their development goals already makes me happy.
And if you would like to contribute to the project you may do it in multiple ways:
1. Submit an issue/bug if you have encountered one.
2. If you know the root of the issue please feel free to submit a pull request, just make sure that all tests pass and if the fix needs new unit tests, please add one.
3. Let me and community know if you have any ideas or suggestions on how to improve the project by submitting an issue on GitHub, I will label it as a 'future enhancement'.
4. Feel free to connect with me on LinkedIn and if you wish to let me know how you use DynamicsWebApi` and what project you are working on, I will be happy to hear about it.