"Streamlining Dynamics 365 Integration: Setting Up Postman and CRUD Operations on Data Entities"
Review:
Before learning how to create a D365 Data entity, take a minute to review what data entities are:
A data entity is a logical unit that represents a real-world object, concept, or event in a database or information system. It typically serves as the foundational building block for organizing and structuring data. Data entities are used to describe and encapsulate related information in a way that is easy to manage, analyze, and understand.
Key Characteristics of a Data Entity:
Representation of a Concept:
A data entity represents something meaningful, such as a person, product, transaction, or event.
Example: A "Customer" entity may represent individuals purchasing goods or services.
Attributes (Properties):
Data entities have attributes (fields or columns) that store information about the entity.
Example: A "Customer" entity might have attributes like
Name
,Email
,Phone Number
, andAddress
.
Uniqueness:
Each instance of a data entity is uniquely identifiable, often using a primary key or unique identifier.
Example: A "Customer ID" ensures that each customer is distinct in the system.
Relationships:
Data entities may have relationships with other entities.
Example: A "Customer" entity might be related to an "Order" entity to represent that a customer placed an order.
Persistence:
- Data entities are often stored in databases or other data storage systems for long-term use.
Example in Context:
In a database for an e-commerce system:
Entities:
Customer: Represents the buyers.
Order: Represents purchases made.
Product: Represents items for sale.
Attributes:
Customer: Name, Email, Address, Phone Number.
Order: Order ID, Customer ID, Date, Total Amount.
Product: Product ID, Name, Price, Stock Level.
Relationships:
- Each Order is linked to a specific Customer and includes one or more Products.
Importance of Data Entities:
Organization: Help in structuring data logically.
Efficiency: Simplify data management and retrieval.
Scalability: Allow systems to handle more data as they grow.
Clarity: Make systems easier to understand and maintain for developers and analysts.
Create A D365 Data Entity
First, open a D365 project in Visual Studio. Open Project as you Created to make the table
If you are not done with Table Creation in D365fo, First Create project and Create Table
To Create Table in D365 follow this https://dynamics365musings.com/how-to-create-a-table-in-d365/
Second Create the model first on how to create a model in D365. However, I will also explain the steps as well.
Create A Model
First, run Visual Studio as administrator.
Next, go to the Dynamics 365 menu. (If you don’t see the Dynamics 365 menu, go to Extensions>Dynamics 365)
Select Model Management>Create model>Model Management
Note, if you are not running Visual Studio as an Administrator, you will see an error message like the following. Close Visual Studio. Then, right click on the Visual Studio icon, and select ‘Run as Administrator’.
A ‘Create model’ wizard will appear.
First, enter the name of your model into the Model name field.
Secondly, enter the name of your company in the Model publisher field.
Thirdly, enter a value from the drop down in the Layer field. It would take a longer explanation to explain when you should use value. I recommend you set ’CUS’ for now.
Fourthly, enter a description of the functionality in your model for the Model description field.
Next, enter a value for the Model display name.
Finally, click the ‘Next' button.
Select Package
On the next page of the wizard, select ‘Create new package‘. The other option, ‘Select existing package’ should really no longer be used. And is there for support of some old ways of using models.
Click the Next button.
You can update the referenced packages later. if you don’t know at this time, that is ok. It is recommended that you start by selecting the ‘Application Platform and ‘Application Foundation. But you very likely will need to come back and reference more later.
Click the Next button.
Summary
The last page of the wizard is the Summary screen. This screen will list the values you selected throughout the wizard.
Click on Finish.
Second, right click on the project, select properties after that a page will open then select
model name as you create model select the model
Additionally, set the Synchronize Database on Build property to True.
Click on ok.
Add a new data entity to your project
First, right click your project, and select Add>New Item.
Second, select ‘Data Entity from the list. Next, enter ‘TutrishabhEntity’ as the name. Or, come up with your own name. Then, click the ‘Add ‘button.
The Data Entity Wizard will open.
Set the Primary Data Source and Public Entity Name
When you create a D365 Data Entity, you need to specify a primary data source.
First, set the ‘Primary data source to the main table or view you want your data entity to interact with
For this example, set the ‘primary DataSource property to TutTablerishabh. This should be the parent table that is always present. There may be exist child tables that relate to this main table that do not always exist.
Secondly, set the public entity name to ‘Tutrishabh‘. And, set the public collection name to ‘Tutrishabhs‘. This is important to remember as these are the names that will be used by an outside system to interact with your data entity.
You should not need to change the rest. Finally, click the ‘Next 'button.
For more information about these properties, see this Microsoft documentation.
Specify The Fields
ensure that all of the checkboxes on the Primary Address data source fields are checked. Also, rename the ‘Data entity field name’ fields to match the following screenshot.
ensure that all of the checkboxes on the Primary Address data source fields are checked. Also, rename the ‘Data entity field name’ fields to match the following screenshot.
Finally, click the ‘Finish 'button.
Notice, the data entity ‘TutrishabhEntity’ was added to your project.
After that,
Build Your Project
After you create a D365 data entity you must build your project so that the views and tables are creating on the SQL server database.
Next, in Visual Studio, click Build>Build solution. Validate that the build was success and that there were no errors.
Validate the Public Entity Name
Right click the data entity node and select ‘Properties ‘. Validate the properties are correct. Often, users may want to change the ‘Public Collection Name’ or ‘Public Entity Name’ to something different. Ensure the ‘Is Public 'flag is set to Yes.
For this example, set the ‘Label’ to "‘Tablerishabhs’ as same as collection name.
Add Fields
Optionally, you can add or remove fields from your data entity.
To add a field, drag the field from the data source Fields nodes to the Fields nodes of the data entity.
Finally, in Visual Studio, go to Build>Build Solution once more. This will cause the SQL server database to get updated as well.
Afterwards, you can open the staging table and validate that all the fields are listed.
To see the name of the staging table, right click on the data entity, and select ‘Properties’. Next, see the value of the ‘Data Management Staging Table’ property.
Additionally, validate that there exists an index. The index will have all the fields in the data entity EntityKey plus the Definition Group and Executional fields.
Data Management Workspace
After you create a D365 data entity, you can see it in the Data Management Workspace.
In Microsoft Dynamics 365 for Finance and Operations, search for ‘Data management 'in the top bar. Select ‘Data management 'under System administration>Workspaces.
Next, once the page opens, click on the ‘Data entities 'title.
Scroll down or filter until you see the entity that you created. If you do not see it, ensure you have the ‘Synchronize on Build’ property on your project set to ‘True’, and build your solution again.
Now it’s done.
Now,
What is Postman and uses?
Postman is a popular collaboration platform for API development. It is primarily used to design, test, and document APIs in a user-friendly way. Postman provides developers with tools to send requests, inspect responses, and automate testing, making it an essential tool in the software development lifecycle.
Key Features of Postman:
API Request Builder:
Allows users to craft and send HTTP requests (GET, POST, PUT, DELETE, etc.) to APIs.
Supports multiple protocols like REST, Graph012, and SOAP.
Environment Management:
- Manage variables (e.g., API keys, URLs) for different environments like Development, Testing, and Production.
Automation with Collections:
Save and organize requests into collections for reusability.
Automate workflows with collection runners.
Testing and Validation:
Write tests using JavaScript to validate API responses.
Perform assertions on status codes, response times, headers, and body content.
Collaboration:
Share collections, environments, and APIs with team members.
Use Postman Workspaces to collaborate in real-time.
API Documentation:
Generate API documentation automatically based on collections.
Publish and share documentation with stakeholders.
Mock Servers:
- Simulate API endpoints with mock servers for testing without backend dependencies.
Integration:
- Integrates with tools like Jenkins, GitHub, and CI/CD pipelines to support DevOps practices.
Uses of Postman:
API Testing:
Test the functionality, performance, and reliability of APIs.
Validate that APIs return the correct responses for various inputs.
Debugging APIs:
Troubleshoot API issues by sending requests and analyzing responses.
Inspect request and response headers, body, and status codes.
Automated Testing:
Automate repetitive testing tasks with Postman scripts and runners.
Integrate automated tests into CI/CD pipelines for continuous testing.
API Documentation:
- Create and publish interactive API documentation for developers to understand and use APIs effectively.
API Development:
Prototype and test APIs during the development phase.
Verify and refine endpoints before production.
Collaboration:
- Facilitate teamwork between developers, testers, and API consumers by sharing collections and environments.
Mocking APIs:
Simulate APIs that are under development or unavailable.
Allow frontend and backend teams to work in parallel.
Performance Testing:
- Assess the speed and efficiency of APIs under different conditions.
Who Uses Postman?
Developers: For building and testing APIs during development.
Testers: To perform manual or automated testing of APIs.
DevOps Engineers: For integrating API testing into CI/CD workflows.
API Consumers: To understand how to interact with APIs using the generated documentation.
Why is Postman Important?
Postman simplifies API workflows, improves productivity, and enhances collaboration among teams. Its versatility makes it suitable for various stages of the API lifecycle, from development to deployment and beyond.
Use Postman To Call D365 Data Entities
Setup Steps
First, download Postman from the following link: https://www.postman.com/downloads/
Next, before we setup Postman to call D365 Data Entities we need to do two things first:
Register an Azure Portal App
Register the external application in D365
These steps only need to be done once. I will go over these steps in this article. And then cover the actual postman setup steps in the next article.
Register an Azure Portal App
Go to portal.azure.com and login.
Register the Azure Application
Click on the hamburger in the top right corner, and then select ‘Azure Active Directory’.
Write down the ‘Tenant ID’ or copy it in notepad. We will need it later. We will refer to this as the Directory ID.
Next, select ‘App registrations’ then click the ‘+ New registration’ button.
Then click the Register button.
Create The Client Secret ID
Select ‘Certificates & secrets. Then click the ‘+ New client secret’ button.
Enter in a Description for the client secret.
Set the Expires value.
Then click the ‘Add’ button.
Write down the value shown. We will need it later. Going forward we will call this the ‘client secret ID‘.
Register the external application in D365
Use a browser, and login to your D365 instance.
Then go to System administration > Setup > Azure Active Directory applications.
Select New.
Fill in the field ‘Client ID’ with the client that you wrote down after registering the app earlier in this article.
Enter in a name.
Enter in a user ID that has appropriate permissions to allow for the data entities to be called. Initially for testing, you can set this to a user ID with system administrator privileges. Then click Save.
Setup Postman to Call D365 Data Entities
Before we actually make the call to the data entity. We will need to do two things first:
Create Get Token Request in Postman. This will get an access token needed to access D365.
Store the Access Token in an Environment Variable.
What You Will Need
In order to use Postman, you will need the following pieces.
Download and install Postman. https://www.postman.com/downloads/
The Directory ID.
The Client ID.
The Client Secret ID.
The URL of the D365 environment you wish to connect to.
Create Get Token Request In Postman
Open Postman.
Click the ‘New’ button in the top right corner. Select ‘Request’.
In the Dialog that open, enter in a Request name. Then click Save.
In the main window, change the request type to be ‘Post’.
Then enter in the URL to be the following. Replace <Directory ID> to be your Directory ID found in the Azure Portal.
https://login.microsoftonline.com/<Directory ID>/oauth2/v2.0/token
Next, select the ‘Headers’ tab and specify the following values. Most should be defaulted in. However, you will need to set the Host to login.microsoftonline.com.
Click on the Body tab and specify the following Key Value pairs.
The ClientID should be the Client ID found in Azure Portal.
The client secret should be the Client Secret ID found in the Azure Portal.
The grant type should be the text ‘client credentials ‘.
The Scope should be set to the URL of your D365 instance that you wish to connect to, followed by the text ‘/.default
https://<D365 URL>/.default
Click the ‘Save’ button in the top right to save the request.
Click the ‘Send’ button. If you have setup the request correctly, you will see something similar in the response body. The access token value will contain a long string. And the Status will be 200 OK.
Store the Access Token in An Environment Variable
We will need to use the access token value from the last step, whenever we make a call to D365. This token expires in about an hour. While we could regularly copy and paste the long string into our request, there is an easier way. We can have postman store it in an environment variable.
In Postman, click the New button. Then select ‘Environment’.
In the dialog that opens specify a name for the environment. In the first line, enter the text ‘access token’ under the variable column. Then click the Add button.
Now go back and select the ‘Get Token’ request.
Select the ‘Script’ tab.
Enter the following code. This takes the access token value in the response of this request, and stores it in the environment variable named ‘access token’.
var jsonData = pm.response.json(); postman.setEnvironmentVariable("access_token1", jsonData.access_token);
Push ‘Save’.
Next, in the top right corner, select the name of your environment from the drop down.
Then click ‘Send’ on the ‘Get Token’ request. This will cause the access_token in the response to be stored in the environment variable named ‘access_token’.
Setup Postman Request To D365 Data Entity
Finally, we can make a request to the D365 Data entity.
In Postman, click the ‘New’ button. Then select ‘Request’.
Set the request type to ‘Get’.
Specify the following text in the URL field. Replace <D365 URL> with the URL you use to access the D365 environment.
https://<D365 URL>/data/Tablerishabhs
Most of the pairs will default in. However, you will need to set the Authorization value to the text ‘Bearer {{access token}}’. This tells Postman to replace the text ‘access token’ with the value in the access token environment variable.
If you do not setup an environment variable, manually copy and paste the long access token value from the first call into this field. Note, keep the ‘Bearer {{}}’ text.
Click ‘Save’
Click ‘Send’
If you set things up correctly, you will get a response with a Status of 200 Ok. And you will see customer data returned as JSON text in the response.
Now let’s start with CRUD operation
What is CRUD ?
In Dynamics 365 (D365), CRUD operations refer to the four basic functions that are performed on data entities:
Create: Add new records to the system.
Read: Retrieve and view data.
Update: Modify existing records.
Delete: Remove records from the system.
These operations are fundamental to working with data in any application, including D365, and are commonly used in OData services, custom development, and integrations.
Step by Step guide to perform Operation:
1. Create
Purpose: To add new data records in the system.
Method:
POST
Example: To create a new customer, select a
POST
request with the necessary data to the appropriate entity:Write down the URL same as in Get new request
Click on body >raw and copy this format from Get new request result.
After click to send
-
Now it's done,
After that if you will see in frontend then data will show you as you created.
2. Read
Purpose: To retrieve and view data from the system.
Method:
GET
Example: To fetch details of a specific customer:
Write down the URL and write the data which you want to read as seen in example below and click on send simple.
-
3. Update
Purpose: To modify existing data records.
Method:
PATCH
(preferred for partial updates) orPUT
(for full updates).Example: To update the address of an existing customer:
Write down the URL with data name as you want to update.
Click on body>raw and write the data format as seen below which you want to update then click send
Updated data will be shown in frontend
-
4. Delete
Purpose: To remove a record from the system.
Method:
DELETE
Example: To delete a specific customer record:
Write the URL and data name which you want to delete
Click on body>raw and write the data format as you want to delete
Click on send after that Data will delete from frontend.
-
Now CRUD Operation is Done.
How CRUD Works in Dynamics 365:
Entities: CRUD operations are performed on data entities that expose tables and their associated data in D365.
OData Services: CRUD operations use OData (Open Data Protocol) for API requests.
Custom Development: Developers can extend or create custom entities and expose them for CRUD operations.
Key Considerations for CRUD in D365:
Security Roles: Ensure the user performing CRUD operations has appropriate privileges.
Data Validation: Dynamics 365 enforces validations and business rules when performing CRUD.
Integration: Use CRUD operations for system integrations via APIs.
Performance: Consider data volumes and performance impacts when using batch operations for multiple CRUD actions.
Conclusion
Conclusion of Successfully Setting Up Postman and Data Entities for CRUD in D365
Successfully setting up Postman and performing CRUD operations on Data Entities in Dynamics 365 (D365) is a significant milestone in integrating and managing your system. Here’s a summary of key takeaways:
1. Streamlined Integration with D365
By configuring Postman, you can efficiently test and manage data entities using RESTful APIs exposed by Dynamics 365.
This setup facilitates seamless communication between external systems and D365, enhancing data flow and integration capabilities.
2. Mastery of CRUD Operations
Create, Read, Update, and Delete operations allow you to:
Add new data records (e.g., customers, vendors).
Retrieve existing data for reporting or validation.
Modify and update records based on business needs.
Delete obsolete or incorrect records securely.
These operations provide full control over data management in D365 and can be extended to custom entities for specific business requirements.
3. Enhanced Development and Testing
Using Postman simplifies:
Authentication: Testing with OAuth tokens ensures secure access.
Data Validation: Sending structured payloads (JSON/XML) helps ensure data consistency.
Error Handling: Immediate feedback on incorrect requests helps debug and improve API usage.
4. Improved System Efficiency
Automated testing and batch processing of data entities reduce manual effort and errors.
CRUD operations optimize workflows by enabling programmatic updates, reducing the time spent on routine tasks.
5. Foundation for Advanced Scenarios
With Postman and CRUD operations in place, you can now:
Build advanced integrations with third-party systems.
Automate workflows using custom scripts and tools.
Extend D365 functionality with tailored solutions (e.g., Power Automate or Azure Logic Apps).
Next Steps
Ensure Security:
Regularly review user permissions and security roles for CRUD operations.
Protect access to Postman by securing your API tokens and credentials.
Refine Usage:
Use OData queries (
$filter
,$orderby
,$top
) for efficient data retrieval.Leverage Postman collections to organize and reuse API requests.
Monitor and Optimize:
Track system performance for bulk CRUD operations.
Implement logging for audit trails of CRUD activities.
Scale and Extend:
Explore automating repetitive tasks using APIs.
Incorporate CRUD into CI/CD pipelines for rapid deployment of integrations.
By successfully setting up Postman and mastering CRUD operations in Dynamics 365, you have laid the groundwork for robust system integration, efficient data management, and the ability to meet evolving business needs. Let me know if you'd like further assistance with scaling or optimizing your setup!