You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At this moment DynamicsWebApi does not fetch authorization tokens, so you will need to acquire OAuth token in your code and pass it to the DynamicsWebApi.
135
-
Token can be aquired using [ADAL for Node.js](https://github.com/AzureAD/azure-activedirectory-library-for-nodejs) or you can write your own functionality, as it is described [here](http://alexanderdevelopment.net/post/2016/11/23/dynamics-365-and-node-js-integration-using-the-web-api/).
139
+
Token can be aquired using [MSAL for JS](https://github.com/AzureAD/microsoft-authentication-library-for-js) or you can write your own functionality, as it is described [here](http://alexanderdevelopment.net/post/2016/11/23/dynamics-365-and-node-js-integration-using-the-web-api/).
136
140
137
-
Here is a sample using `adal-node`:
141
+
Here is a sample using `@azure/msal-node`:
138
142
139
143
```js
140
-
var DynamicsWebApi =require('dynamics-web-api');
141
-
var AuthenticationContext =require('adal-node').AuthenticationContext;
142
-
143
-
//the following settings should be taken from Azure for your application
144
-
//and stored in app settings file or in global variables
145
-
146
-
//OAuth Token Endpoint
147
-
var authorityUrl ='https://login.microsoftonline.com/00000000-0000-0000-0000-000000000011/oauth2/token';
148
-
//CRM Organization URL
149
-
var resource ='https://myorg.crm.dynamics.com';
150
-
//Dynamics 365 Client Id when registered in Azure
151
-
var clientId ='00000000-0000-0000-0000-000000000001';
152
-
var username ='crm-user-name';
153
-
var password ='crm-user-password';
144
+
//app configuraiton must be stored in a safe place
145
+
importConfigfrom'./config.js';
146
+
importDynamicsWebApifrom'dynamics-web-api';
147
+
import*asMSALfrom'@azure/msal-node';
154
148
155
-
var adalContext =newAuthenticationContext(authorityUrl);
149
+
//OAuth Token Endpoint (from your Azure App Registration)
150
+
constauthorityUrl='https://login.microsoftonline.com/<COPY A GUID HERE>';
156
151
157
-
//add a callback as a parameter for your function
158
-
functionacquireToken(dynamicsWebApiCallback){
159
-
//a callback for adal-node
160
-
functionadalCallback(error, token) {
161
-
if (!error){
162
-
//call DynamicsWebApi callback only when a token has been retrieved
163
-
dynamicsWebApiCallback(token);
164
-
}
165
-
else{
166
-
console.log('Token has not been retrieved. Error: '+error.stack);
167
-
}
152
+
constmsalConfig= {
153
+
auth: {
154
+
authority: authorityUrl,
155
+
clientId:Config.clientId,
156
+
clientSecret:Config.secret,
157
+
knownAuthorities: ['login.microsoftonline.com']
168
158
}
159
+
}
169
160
170
-
//call a necessary function in adal-node object to get a token
console.log(`Hello Dynamics 365! My id is: ${response.UserId}`);
186
+
}
187
+
catch (error){
188
+
console.log(error);
189
+
}
190
+
186
191
```
187
192
188
193
### Configuration
@@ -1011,7 +1016,7 @@ Batch requests bundle multiple operations into a single one and have the followi
1011
1016
* Provides a way to run multiple operations in a single transaction. If any operation that changes data (within a single changeset) fails all completed ones will be rolled back.
1012
1017
* All operations within a batch request run consequently (FIFO).
1013
1018
1014
-
DynamicsWebApi provides a straightforward way to execute Batch operations which may not always simple to compose.
1019
+
DynamicsWebApi provides a straightforward way to execute Batch operations which may not always be simple to compose.
1015
1020
The following example bundles 2 retrieve multiple operations and an update:
Note that the second response does not have a returned value, it is a CRM Web API limitation.
1120
+
Note that if you are making a request to a navigation property (`collection: 'customerid_contact'`), the request won't have a response, it is an OOTB Web API limitation.
1116
1121
1117
1122
**Important!** DynamicsWebApi automatically assigns value to a `Content-ID` if it is not provided, therefore, please set your `Content-ID` value less than 100000.
**Important!** Web API seems to have a limitation (or a bug) where it does not return the response with `returnRepresentation` set to `true`. It happens only if you are trying to return a representation of an entity that is being
1160
+
linked to another one in a single request. [More Info and examples is in this issue.](https://github.com/AleksandrRogov/DynamicsWebApi/issues/112).
1161
+
1154
1162
#### Limitations
1155
1163
1156
1164
Currently, there are some limitations in DynamicsWebApi Batch Operations:
0 commit comments