Sitecore Commerce APIs are based on OData. When Storefront makes call to Sitecore Commerce Engine, it uses OData clients, which are Commerce Services Proxy generated using T4 templates. If you download Sitecore Commerce SDK, you will find the several Postman Collections, which are json files you can load in Postman tool and fire the OData APIs. Postman is very useful to debug OData APIs but, I find Fiddler is useful for this purpose too. What I find useful in fiddler is, when I am debugging code in Visual Studio or just using the website (storefront), if I would like to see the OData APIs in use, I can see that in Fiddler. Once, I capture the API in Fiddler, I can replay it in Fiddler Composure as many time as I want.
In this blog, I will discuss, how we can setup Sitecore Commerce, so that, we can capture the OData APIs in Fiddler. We will be using Sitecore Storefront, so setup starts from there. The OData API calls are made from ASP.NET server side code. How can we setup the Storefront application, so that, this API calls from the server side code can go through Fiddler. Here is how.
Open up the web.config file for Storefront and add the following in that file
You can find more information in telerik website here
Once that change is made OData calls will be routed through Fiddler, but still it cannot be seen in Fiddler because, base URL for the Commerce Engine site is setup as http://localhost:5000 per Sitecore installation instruction. Fiddler doesn’t capture traffic on the localhost. So, we have to use a different base URL.
First setup a different binding for Commerce Engine site. Open up the site in Internet Information Manager and changed the binding as follows and removed the binding with empty Host Name.
To access the site on that binding you need to add that in the host file. Open up the host file and add 127.0.0.1 commeceauthoring as a new entry. Now, if you go to browser and access http://commerceauthoring:5000/api/$metadata you will see the OData metadata information for Commerce Engine.
Next open up Sitecore.Commerce.Engine.config and Z.Sitecore.Commerce.UX.Shared.config in Storefront and replace localhost with commeceauthoring. Setup is ready now to capture the Sitecore Commerce OData APIs in Fiddler.
Start fiddler and make sure you are capturing traffic from all processes, not only from the browser. Now, if you open the storefront site in browser, traffic will be captured as shown below. This was captured when I went to product detail page.
If you select the request, you can see the request and response on the right.
You can right click on the captured request and go to Replay -> Reissue from Composure to debug the request in Fiddler Composure. You can change request parameters and play with the API.
That’s it. Happy debugging!
Update: When you are done with the debugging make sure to remove the configuration from the web.config. If that configuration is there and you are not running Fiddler while using the site, you will see errors in the application because, there is no way to route the request to Fiddler.