![]() |
VOOZH | about |
The CData API Server, when paired with the Microsoft Dataverse connector (or any of over 300 supported data sources), exposes Microsoft Dataverse data as an OData web service that can be queried from Node.js using simple HTTP requests. This article walks you through setting up the CData API Server and demonstrates the process to retrieve JSON-formatted Microsoft Dataverse data in Node.js.
CData provides the easiest way to access and integrate live data from Microsoft Dataverse (formerly the Common Data Service). Customers use CData connectivity to:
CData customers use our Dataverse connectivity solutions for a variety of reasons, whether they're looking to replicate their data into a data warehouse (alongside other data sources)or analyze live Dataverse data from their preferred data tools inside the Microsoft ecosystem (Power BI, Excel, etc.) or with external tools (Tableau, Looker, etc.).
If you haven't already, download and install the CData API Server. After installation, run the application, download the Microsoft Dataverse connector from within the API Server, and configure your Microsoft Dataverse data connection. Then, configure API Server to generate OData feeds for any tables you want to access in your single-page application (SPA).
AngularJS requires servers to have CORS (Cross-Origin Resource Sharing) enabled. To enable CORS, go to the Server tab under the Settings section in the API Server and adjust the following settings:
To work with Microsoft Dataverse data using AngularJS, we start by creating and configuring a Microsoft Dataverse connection. Follow the steps below to configure the API Server to connect to Microsoft Dataverse data:
Next, create a user to access your Microsoft Dataverse data through the API Server. You can add and configure users on the Users page. Follow the steps below to configure and create a user:
Having created a user, you are ready to create API endpoints for the Microsoft Dataverse tables:
Having configured a connection to Microsoft Dataverse data, created a user, and added resources to the API Server, you now have an easily accessible REST API based on the OData protocol for those resources. From the API page in API Server, you can view and copy the API Endpoints for the API:
π API EndpointsJust like with standard OData feeds, you can limit the fields returned by adding a $select parameter to the query. You can also include other standard OData URL parameters, such as $filter, $orderby, $skip, and $top. Refer to the help documentation for more details on supported OData queries.
Select the user you created, then copy and save the authtoken for future use. You can also toggle on 'Token Expiration' and set the number of days based on your use case. Click Save to save the details.
π Copy and save authtokenOData feeds provide a standardized way to access data and can be easily consumed in Node.js. Node.js scripts use the built-in http module to make requests to the CData API Server, which acts as an intermediary to expose Microsoft Dataverse data as OData. The process involves constructing HTTP GET requests to the API Server's OData endpoints, handling the responses, and parsing the JSON data.
To get started, we'll create a new Node.js project and install the necessary packages to run it.
cd D:\ mkdir my-odata-app cd my-odata-app npm init -y
npm install http
In this section, we'll work on retrieving specific records from a Microsoft Dataverse entity by filtering based on a unique identifier using the app_data.js script.
var http = require('http');
// Function to fetch data based on a given Id
function fetchDataById(id) {
http.get({
protocol: "http:",
hostname: "localhost",
port: 8080,
path: "/api.rsc/DEMO_DB_CRM_Account?$filter=" + encodeURIComponent("Id eq '" + id + "'"), // Updated URL with filter
auth: 'your_username:your_authtoken' // Enter your username and authtoken/password
}, function (res) {
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
var jsonData = JSON.parse(body);
console.log(jsonData);
});
}).on('error', function (e) {
console.log("Error: ", e);
});
}
// Example usage: Fetch data for Id '11'
fetchDataById('11');
Retrieve the specific records for an unique identifier from the Microsoft Dataverse entity, using the following command in the Terminal or Command Prompt:
node app_data.js
The app_table.js script focuses on fetching all records from a specified Microsoft Dataverse entity.
var http = require('http');
http.get({
protocol: "http:",
hostname: "localhost",
port: 8080,
path: "/api.rsc/DEMO_DB_CRM_Account", // Updated URL to fetch data from DEMO_DB_CRM_Account
auth: 'your_username:your_password' // Enter your username and password/authtoken
}, function (res) {
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
console.log(body);
var jsonData = JSON.parse(body);
console.log(jsonData);
});
}).on('error', function (e) {
console.log("Error: ", e);
});
Retrieve all the records from the Microsoft Dataverse entity, using the following command:
node app_table.js
Accessing Microsoft Dataverse data from Node.js can be greatly simplified by leveraging an OData API. CData API Server exposes Microsoft Dataverse data as an OData service, enabling you to perform "Read" operations using standard HTTP requests. This allows you to work with your Microsoft Dataverse data in a more structured and standardized way.
To see how API Server can simplify your data access, download a free, 30-day trial of CData API Server today! For more general information on our API Server and to see what other data sources we support, refer to our API Server page.Learn more or sign up for a free trial:
CData API Server