Sitecore Commerce 9 provides extensive API that could be used to manipulate products in Commerce database. However it also allows to extend this API by adding custom commerce commands.

In this post I’d describe how to achieve this. One important note to consider is that to extend the API we need to extend the Sitecore Commerce engine. More information how to do that could be found in this great guide by Ryan Bailey here:

https://blog.ryanbailey.co.nz/2018/02/sitecore-experience-commerce-extending.html

Step 1: Create custom command

Lets create custom command class for our API command.

To do that we need to create class that will be inherited from CommerceCommand.

Step 2: Create controller

Now you need to create new API controller that will handle calls to your custom API.

We can pass parameters to our command in request body as JSON properties.

Step 3: Register OData API method

We also need to register our new OData API method by creating custom pipeline block.

Finally we reference newly created block in ConfigureSitecore.cs

And now…. Test it!

Now we should be able to successfully call our API through Postman!

Have fun!