In recent days Node Js becoming quite popular. Different kind of portals and applications are made on Node Js technology because of it’s performance and efficiency.
So it’s becoming important to integrated Dynamics CRM 365 with node JS.
In this blog I will try to explain how we can integrate Dynamics 365 to Node Js with help of Azure Apps.
After
creating azure app we can integrate Dynamics 365 with our other products also.
There are two kind of Azure App which can be used for integration.
1. Native App
2. Web App/ API Application
integration. But the major difference is:-
Password while integrate via Native APP.
application user while integrate via Web App /API APP.
3. You will find two App registration
a) App Registrations.
b) App Registrations(Legacy)
Legacy.
applications” and “All applications”, where we can see all registered Apps.
6. Click
on “New registration” and select below options.
Click
on “Register” button.
7. Copy
and Save Application (client) ID for further use.
8. Click
on Authentication and made below changes and save.
9. Click
on API permission and add Dynamics CRM Online.
10. Grant
admin consent
11. Go
back to App registration and select Endpoints.
and copy Token endpoint(v1)
If
you still want to create Legacy APP, select App registration(Legacy)
1. Provide
information and select Application Type as “Native”.
2. Copy
Application ID to use as Client Id while integration.
3. Click
on settings and select “Required Permissions”.
4. Add
Dynamics CRM Online in permission.
We
can also use Web App /API APP for Integration
3. Add
secret Key and create Application User .
Copy
and Save secret key for further use.
1. (Web
App with Legacy App Registration) Provide information and select Application
Type “Web App/ API”.
on settings and select “Key”.
We can choose one of four (Legacy Native App, Legacy Web App, New Native App, New Web App)
for integration.
Now
our App ready to integrate for other product like Node.Js
1. To
test application Node.js online, open
and paste below code. Update organization and
application information in Code.
//basic query to select contacts
tokenendpoint.toLowerCase().replace(‘https://’, ”);
tokenendpoint.split(‘/’).slice(1).join(‘/’);
encodeURIComponent(username);
encodeURIComponent(userpassword);
authhost,
authpath,
‘POST’,
‘Content-Type’: ‘application/x-www-form-urlencoded’,
‘Content-Length’: Buffer.byteLength(reqstring)
function (response) {
array to hold the response parts if we get multiple parts
responseparts = [];
response.setEncoding(‘utf8’);
response.on(‘data’, function (chunk) {
each response chunk to the responseparts array for later
responseparts.push(chunk);
response.on(‘end’, function () {
we have all the response parts, concatenate the parts into a single string
completeresponse = responseparts.join(”);
completeresponse);
console.log(‘Token response retrieved . . . ‘);
the response JSON
tokenresponse = JSON.parse(completeresponse);
//extract the token
token = tokenresponse.access_token;
the token to our data retrieval function
getData(token);
console.error(e);
web api request headers
requestheaders = {
‘Authorization’: ‘Bearer ‘ + token,
‘OData-MaxVersion’: ‘4.0’,
‘OData-Version’: ‘4.0’,
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json; odata.metadata=minimal’,
‘Prefer’: ‘odata.maxpagesize=500’,
‘Prefer’: ‘odata.include-annotations=*’
crm request parameters
= {
crmwebapihost,
crmwebapipath,
‘Get’,
headers: requestheaders,
web api request
crmrequest = https.request(crmrequestoptions, function (response) {
an array to hold the response parts if we get multiple parts
responseparts = [];
response.setEncoding(‘utf8’);
response.on(‘data’, function (chunk) {
//add each response chunk to the responseparts array for later
responseparts.push(chunk);
response.on(‘end’, function () {
//once we have all the response parts, concatenate the parts into a
single string
completeresponse = responseparts.join(”);
console.log(completeresponse);
//parse the response JSON
collection = JSON.parse(completeresponse).value;
console.log(row[‘fullname’]);
//loop through the results and write out the fullname
crmrequest.on(‘error’, function (e) {
console.error(e);
web api request
crmrequest.end();
token
‘/api/data/v9.1/contacts’; //basic query to select contacts
tokenendpoint.toLowerCase().replace(‘https://’, ”);
tokens work, see IETF RFC 6749 – https://tools.ietf.org/html/rfc6749
encodeURIComponent(crmorg);
Client_secret;
‘&grant_type=client_credentials’;
host: authhost,
path: authpath,
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded’,
‘Content-Length’: Buffer.byteLength(reqstring)
https.request(tokenrequestoptions, function (response) {
//make an array to hold the response parts if we get multiple parts
var responseparts = [];
response.setEncoding(‘utf8’);
response.on(‘data’, function (chunk) {
//add each response chunk to the responseparts array for later
responseparts.push(chunk);
});
function () {
//once we have all the response parts, concatenate the parts into a
single string
var completeresponse = responseparts.join(”);
//console.log(‘Response: ‘ + completeresponse);
console.log(‘Token response retrieved . . . ‘);
//parse the response JSON
var tokenresponse = JSON.parse(completeresponse);
//extract the token
var token = tokenresponse.access_token;
//pass the token to our data retrieval function
getData(token);
});
console.error(e);
//set the web api request headers
var requestheaders = {
‘Authorization’: ‘Bearer ‘ + token,
‘OData-MaxVersion’: ‘4.0’,
‘OData-Version’: ‘4.0’,
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json; odata.metadata=minimal’,
‘Prefer’: ‘odata.maxpagesize=500’,
‘Prefer’: ‘odata.include-annotations=*’
};
//set the crm request parameters
var crmrequestoptions = {
host: crmwebapihost,
path: crmwebapipath,
method: ‘Get’,
headers: requestheaders,
};
//make the web api request
var crmrequest = https.request(crmrequestoptions, function (response) {
//make an array to hold the response parts if we get multiple parts
var responseparts = [];
response.setEncoding(‘utf8’);
response.on(‘data’, function (chunk) {
//add each response chunk to the responseparts array for later
responseparts.push(chunk);
});
response.on(‘end’, function () {
//once we have all the response parts, concatenate the parts into a
single string
var completeresponse = responseparts.join(”);
// console.log(completeresponse);
//parse the response JSON
var collection = JSON.parse(completeresponse).value;
console.log(row[‘fullname’]);
//loop through the results and write out the fullname
});
});
crmrequest.on(‘error’, function (e) {
console.error(e);
});
//close the web api request
crmrequest.end();
‘/api/data/v9.1/dynamicproperties?fetchXml=’ + fetchQuery;























