Senior Software Engineer
Subscribe to the newsletter
Today’s customers expect more than just personalization – they demand speed and accuracy at every touchpoint. For retailers, this means navigating the immense pressure of managing sales orders while ensuring seamless data synchronization across systems and channels. Keeping customer information updated in real-time is crucial for providing a smooth shopping experience and equipping sales teams with accurate data.
Dynamics 365 Commerce addresses this challenge with real-time customer creation capabilities in the Dynamics 365 Modern POS or Dynamics 365 Store Commerce app. This integration, enabled through an API, allows for instant customer creation during transactions, making it particularly valuable in point-of-sale (POS) scenarios.
Curious to see how it works? Our blog provides a detailed implementation guide for real-time customer creation, along with best practices to ensure success.
What is real-time customer creation?
Real-time customer creation ensures that newly created customer records are instantly available across the system. This eliminates delays and enhances operational efficiency in customer-centric processes.
Steps to implement real-time customer creation
Ready to get started with the implementation? Here are the steps to get started:
Step 1: Prerequisites
Before starting, ensure the following:
- A Dynamics 365 instance with Dynamics 365 Commerce is enabled.
- Access the D365 environment’s Azure Active Directory (AAD) app registration.
- Necessary permissions to use D365 APIs.
- An API testing tool like Postman for initial testing.
Step 2: Set up Azure Active Directory authentication
Dynamics 365 APIs use OAuth 2.0 for authentication via Azure Active Directory. The steps below explain how it’s done:
1. Register an app in the Azure Active Directory:
- Navigate to the Azure portal.
- Register an application and note the Application ID and Tenant ID.
2. Generate client secret:
- Create a client secret under the app registration and store it securely.
3. Assign API permissions:
- Assign permissions for Dynamics 365 ERP APIs.
Step 3: Understand the API endpoint
The endpoint for creating customers in Dynamics 365 is part of the OData services:
POST API URL https:///api/services/CreateCustomerServiceGroup/CreateCustomerService/CreateCustomer’
POST Token URL
https:// /oauth2/token
Step 4: Token request structure
Here’s a sample code in C#
API Request Structure
Here’s a sample JSON payload for creating a customer:
{
“Customer”:{
“LegalEntity”:”USRT”,
“FirstName”:”Alex”,
“LastName”:”Trump”,
“ContactNumber”:”+923004000101″,
“CurrencyCode”:”USD”,
“EmailAddress”:”abc1234@gmail.com”,
“DateOfBirth”:”11/10/1997″,
“Gender”:”Male”,
“BillingAddress”:[
{
“Addresstitle”:”Johar town Branch”,
“Street”:”185 aba road safari villas 8888 phase 7 johar town “,
“Addresstype”:”Billing”,
“CountryCode”:”USA”
}
],
“ShippingAddress”:[
{
“Addresstitle”:”Johar town Branch 2″,
“Street”:”185 aba road safari villas 10 phase 7 johar town2″,
“Addresstype”:”Shipping”,
“PrimaryAddress”:”Yes”,
“CountryCode”:”USA”
}
]
}
}
Method to Create Customer in CRT-CommerceRunTime using the above Payload.
Key fields for your understanding
LegalEntity: Best practice
FullName: Full name of the customer.
CustomerGroup: Group classification for the customer.
Address: Address details are nested.
CountryCode is a requirement.
Step 5: Make the API call
Send the request using an HTTP client like Postman or your custom integration code.
Sample cURL Request:
Token generation:
curl –location ‘{}/oauth2/token’ \
–header ‘Host: login.microsoftonline.com’ \
–header ‘Content-Type: application/x-www-form-urlencoded’ \
–data-urlencode ‘client_id=352a446a-9168-491b-b52f-a640164aa215’ \
–data-urlencode ‘client_secret=omw8Q~b-j9bHxM7KIlR6Wt4NUV52vbZVdMPtpb7a’ \
–data-urlencode ‘resource=https://tlcdev20b17a731b7cea57bdevaos.cloudax.uae.dynamics.com/’ \
–data-urlencode ‘grant_type=client_credentials’
CreateCustomer API:
curl –location –globoff ‘{}/api/services/CreateCustomerServiceGroup/CreateCustomerService/CreateCustomer’ \
–header ‘Content-Type: application/json’ \
–header ‘Authorization: Bearer {{access_token}}’ \
–data-raw ‘{
“Customer”:{
“LegalEntity”:”USRT”,
“FirstName”:”Cust”,
“MiddleName”:””,
“LastName”:””,
“ContactNumber”:”+923004000101″,
“CurrencyCode”:”USD”,
“EmailAddress”:”abc1234@gmail.com”,
“DateOfBirth”:”11/10/1997″,
“Gender”:”Male”,
“BillingAddress”:[
{
“Addresstitle”:”Johar town Branch”,
“Street”:”185 aba road safari villas 8888 phase 7 johar town “,
“Addresstype”:”Billing”,
“PrimaryAddress”:”Yes”,
“PostalCode”:”00210″,
“City”:”Acworth”,
“Country”:”USA”,
“CountryCode”:”USA”,
“State”:”NH”
}
],
“ShippingAddress”:[
{
“Addresstitle”:”Johar town Branch 2″,
“Street”:”185 aba road safari villas 10 phase 7 johar town2″,
“Addresstype”:”Shipping”,
“PrimaryAddress”:”No”,
“PostalCode”:”00210″,
“City”:”Alton Bay”,
“Country”:”USA”,
“CountryCode”:”USA”,
“State”:”NH”
}
]
}
}
‘
Replace with your environment URL and with a valid token generated via Azure AD.
Step 6: Handle responses
The API will return one of the following responses:
- 200 created: If the customer is successfully created.
- 400 bad request: For invalid payload or missing fields.
- 401 unauthorized: If authentication fails.
Example response:
Step 7: Integrate customer creation with the Store Commerce app
To integrate customer creation into the Dynamics 365 Store Commerce app, follow these:
- Use data actions to call the API from POS operations.
- Pass customer data from the POS UI to the API.
- Update the POS transaction with the new customer record upon successful creation.
Typescript method to create the customer
Send customer information data in JsonRequest to DataService method for the creation using the method “Customers.getPatientCheckDataActionRequest”
DataService method
RetailServer method name “getCustomerCheckDataAction”
Step 8: Add the customer to POS cart
Here’s the sample code. After getting the right response, add the customer to cart screen using the “customerAccNum(Customer Account Number)” using default Microsoft operation “SetCustomerOnCartOperationRequest”.
Best practices real-time customer creation in Dynamics 365 Commerce
When implementing real-time customer creation in Dynamics 365 Commerce, following best practices ensures a seamless, secure, and efficient process. Here are key considerations to keep in mind:
- Data validation: Ensure all customer data is validated before being sent to the API to minimize errors and maintain data integrity.
- Error handling: Implement reliable error-handling protocols to address failed API calls effectively and ensure smooth operations.
- Logging: Maintain detailed logs of API requests and responses to facilitate debugging and improve issue resolution.
- Security measures: Safeguard API credentials and tokens by using secure storage methods to protect sensitive data.
Conclusion
Implementing real-time customer creation in Dynamics 365 Commerce through Dynamics 365 APIs streamlines operations and enhances efficiency, particularly in retail environments. This integration with the Store Commerce app enables businesses to deliver seamless customer experiences while maintaining data consistency across systems.
Have questions about implementing this feature or need assistance with your project? Contact us at marketing@confiz.com, and let’s explore how we can help!