3

Is there a way to create catalog/product from commerce API? In postman I found example "Add Catalog" but it uses "DoUxActionsaction instead of some REST method like [POST] /Catalogs

I managed to generate client code from metadata ({{OpsApiHost}}/{{ShopsApi}}/$metadata) using Odata Connected Service in VS and tried to use generated method for creating new catalog

_container.AddToCatalogs(new Sitecore.Commerce.Plugin.Catalog.Catalog()
            {
                Name = "Test",
                DisplayName = "Test",
                PriceBookName = "Postman_Price_Book",
                PromotionBookName = "Postman_Promotion_Book",
            });
await _container.SaveChangesAsync();

but SaveChangesAsync throws error

"System.NotSupportedException: No action match template 'Catalogs' in 'CatalogsController'"

Using postman i was able to get all routes

{{OpsApiHost}}/{{OpsApi}}/GetApiRoutes

and PUT/POST for Catalogs ins't present. Is there a way to create catalog/product or do I have to go with DoUxAction

1

In addition to Vlads answer you can also have a look at this plugin, where I implemented a lot of functionality around importing / creating and updating commerce content in general.

https://github.com/Chris1415/Plugin.Sample.Importer

| improve this answer | |
1

You can do it in next wa in a pipeline block:

public class DoActionGenerateCatalog : PipelineBlock<EntityView, EntityView, CommercePipelineExecutionContext>
{
    private readonly CommerceCommander _commerceCommander;

    public DoActionGenerateCatalog(CommerceCommander commerceCommander)
    {
        this._commerceCommander = commerceCommander;
    }

     public override async Task<EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
    {
        var createdCatalog = await this._commerceCommander.Command<CreateCatalogCommand>().Process(context.CommerceContext, name, displayName);

       createdCatalog = await this._commerceCommander.Command<GetCatalogCommand>().Process(context.CommerceContext, name);

    }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.