Its common to update and create items periodically from other applications via the commerce engine API. In most cases the data passed to the commerce engine is a lot simpler than the standard schema for the SellableItem. 

Its also common that the group of developers calling the API is unfamiliar with Sitecore commerce and does not have the time to learn the ins and outs of the schema.

For example, do the callers of the commerce API really need to know what a child component is or even that the SellableItem is the product? Generally, no, they just want to set a value on the product.

In this post we will look at how to create a simplified input JSON schema  and expose it via the API. In part 2 we will create a Azure Function and call the new API method using the proxy.

The new API method supports the following :-

  1. Creation of multiple products and their variants in the same call using a simple JSON format
  2. Specifying the list price

The simplified input will look like this…

The following is covered in this post :-

  • Create a new pipeline and block to handle the upsert of the sellableitem from a simplified JSON format
  • Create a new function that accepts a simplified JSON format and expose it via the API. This function will also allow the upsert of more than product at a time.
  • Test the new function via Postman 

Step 1 – Create the plumbing

  • In the Commerce Engine SDK create a new plugin and reference it from the engine
  • Add the following code to create the plumbing required to support the the API method.

In folder named “Pipelines\Arguments” create…

In a folder named “Pipelines” create…

In a folder named “Pipelines\Blocks” create…

In a folder named “Commands” create…

Step 2 – Create the new API method

In a folder called “Controllers” create…

In the root of the project create…

Your project should look like this…

Step 3 – Test with Postman

Deploy…

  • Build the solution
  • Start the engine in console mode

Test…

  • Place a break point in the ApiController.CreateUpdateSellableItem method
  • Open postman and import the example postman code from this JSON…
  • Once the example postman call is created from the JSON above, you should be able to execute the postman call and your break point will be hit. You can step through the process until the block that handles the upsert of the product is run.
  • The example Postman command should look like the image at the top of this post.