web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested Answer

How to call a custom API in the commerceSDK from Postman

(2) ShareShare
ReportReport
Posted on by 1,457
In the CRT in the commerceSDK, I have a controller class called ProcessHQFormControllerTMC.
Inside this controller is my method or API I have seen it called:
 
[HttpPost]
[Authorization(CommerceRoles.Application, CommerceRoles.Customer, CommerceRoles.Employee)]
public async Task<string> TMCProcessSalesHubHQForms(IEndpointContext context, string paramData)
{
    HQFormFromSalesHubRequestTMC request = new HQFormFromSalesHubRequestTMC(paramData);
    HQFormFromSalesHubResponseTMC response = await context.ExecuteAsync<HQFormFromSalesHubResponseTMC>(request).ConfigureAwait(false);

    return response.errorMsg;
}
In the end I will have to call this from Power Automate.
The business case is to add an action control button on SalesHub grid which will call the Power automate flow which will call the CRT code.
 
However I am trying to test it in Postman, but I can't get it to work.
Please note, I am testing this inside my Development environment which is an RDP ( cloud-hosted environment)..
 
I used the below 2 documents to do the setup for the AAD token. 
 
 
The documentation isn't clear about the User ID I should use when adding the entry in the Microsoft EntraID application, so I used RetailServerAccount, similar to what I use for the retail server and async client entra IDs for the IIS-Hosted scale unit on my Dev box.
 
Retrieving the token itself works in Postman.
Also, adding the POST request for adding a customer in HQ using the standard API Customers/CreateCustomer which is in the documents links above as an example, work as well. The record is created successfully in HQ.
 
IT added for me the following permissions in Azure Portal for the app registration they added that I'm using in the identity providers and Entra ID setup in HQ:
 
 
As I said, calling the standard CommerceSDK API to create a customer in HQ via Postman, works correctly.
Which means the AAD setup and the setup inside HQ on the identity provider and Application entra ID, is correct.
 
However I cannot get it to work with my custom API.
 
As you can see from the above code snippet, it wants the IEndpointcontext and the paramData as arguments.
I don't know where it gets the IEndpointContext from, I can only assume it is generated with the parameter oun-header entry which have the value of the operating unit number of the retail store I'm using.
 
My parameters for Header:
 
 
The setup in the body section:
 
 
 
If I add the request POSt as follow, then I get a 404-error that it can't find it:
{{General_RetailServer}}/Commerce/ProcessHQFormControllerTMC/TMCProcessSalesHubHQForms?api-version=7.3
If I replace ProcessHQFormControllerTMC with StoreOperations, becasue the latter is how POS finds it, then I also get the 404-error.
If I call it only as:
{{General_RetailServer}}/Commerce/TMCProcessSalesHubHQForms?api-version=7.3
Then I get the error.
 
 
Can somebody please tell me what I'm doing wrong.
Is the AAD token app permissions incorrect that it can't see the custom, only the standard API's?
Or do I call the custom API incorrect?
However the 500 error looks to me like it can't talk to the retail server as if its down.
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Holly Huffman Profile Picture
    6,530 Super User 2025 Season 2 on at
    Good morning, afternoon, or evening :) depending on your location!
     
    Based on your description, here are some steps to troubleshoot and resolve the problem:
     
    1. Verify API Endpoint
    • Ensure that the custom API endpoint is correctly registered in the Retail Server. Custom APIs need to be explicitly exposed in the Retail Server configuration.
    • Check the route mapping in your controller class. The route should match the URL you're using in Postman:
      {{General_RetailServer}}/Commerce/ProcessHQFormControllerTMC/TMCProcessSalesHubHQForms?api-version=7.3
      If the route is not explicitly defined, the Retail Server may not recognize it.
    2. Check Retail Server Configuration
    • Confirm that the Retail Server is running and accessible. A 500 error could indicate that the server is down or misconfigured.
    • Verify that the Retail Server has been updated to include your custom controller. If the controller is not deployed, the server will return a 404 error.
    3. Validate AAD Token Permissions
    • Ensure that the AAD token has the necessary permissions to access custom APIs. While standard APIs like Customers/CreateCustomer work, custom APIs may require additional permissions.
    • Check the Azure Portal for the app registration and confirm that the following roles are assigned:
      • CommerceRoles.Application
      • CommerceRoles.Customer
      • CommerceRoles.Employee
    4. Debug IEndpointContext
    • The IEndpointContext is typically provided by the Retail Server during runtime. It is not something you pass explicitly in Postman.
    • Ensure that the oun-header parameter in your request matches the Operating Unit Number of the retail store you're testing against.
    5. Test with Standard APIs
    • Since standard APIs work correctly, use them as a baseline to confirm that your setup (headers, token, etc.) is correct.
    • Compare the request structure for the standard API with your custom API to identify discrepancies.
    6. Check Controller Authorization
    • Verify that the [Authorization] attribute in your controller includes the correct roles. If the roles are mismatched, the Retail Server may reject the request.
    7. Use Fiddler or Debugging Tools
    • Use Fiddler or similar tools to capture the HTTP request and response. This can help identify issues with headers, body, or URL formatting.
    8. Deploy and Test in a Sandbox
    • If the issue persists, deploy the custom API to a sandbox environment and test it there. This can help isolate the problem.
     
     
    Hope this helps!
  • Retha Profile Picture
    1,457 on at
    I found the problem. All the setup was correct, hence the reason the standard APIs worked.
    I called the wrong request in the CRT code that Postman called. I copied the code from another and didn't notice that I haven't changed all the references of the request name to the new request name.
  • Holly Huffman Profile Picture
    6,530 Super User 2025 Season 2 on at
    Awesome - that's a great start to the week to find the issue so quickly! 
    hope you have a great rest of your week :) 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Siv Sagar Profile Picture

Siv Sagar 266 Super User 2025 Season 2

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 213 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 140 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans