Developer forum

Forum » Development » How to work webapi Products with Parameters

How to work webapi Products with Parameters

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

I am having some difficulties getting the Products endpoint on the webapi to work as expected:

  • I am using a Swift 1.14.1 site with Dynamicweb 9.13.11
    https://dev-swiftrizzo.mydwsite1.com/
     
  • I need to use the products endpoint being the only one as POST
    /dwapi/ecommerce/product
     
  • I looked into the ProductListViewModelSettings to submit the proper Parameters for the Query
    There are 3 required ones and I submitted my important one MainProductID (which exists in the Products query of the SwiftProducts repository)
     

I can get a response, but it seems to disregard my parameters

Here are my settings

I am attaching the response I get from Swagger

 

Notice how the response does not care about PageSize, CurrentPage nor the Product Ids. It just gives me 10 product ids (when I'm expecting 1).

 

What am I doing wrong?

Best Regards,

Nuno Aguiar


Replies

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply
This post has been marked as an answer

Hi Nuno,

It is a bit confusing, since some of the parameters are not relevant for the webapi, but they are presented due to the underlying viewmodel.

So, the actual model is presented by the schema:



As you can see PageSize is one of them. Setting a PageSize does indeed work for me when testing. But as you can see you are also using some parameters that are not made available by the viewmodel.

Other presented parameters, such as Products and Groups are a wild goose chase in this context, as they will have no affect. They are presented because they are part of the viewmodel, but they are not considered in relation to the webapi. It is work in progress to have this streamlined, we just haven't gotten around to it yet.

All filtering should happen via parameters that apply to the repository query you point to in the request. This should not be handled by the body parameters of the POST request.

Also, it seems to me that you have some syntax error in your body section, as you are missing a colon and some commas to separate each parameter. This example works well for me:

Let me know if the above helped to shed some light on the issue you encounter.

BR
Snedker

Votes for this answer: 1
 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Nuno,

1) Ensure that the request body contains valid json. You are missing a colon and some commas.
2) Ensure that the request body matches the expected schema. You need to include your parameters in a "Parameters" property.

You can see the schema for ProductListViewModelSettings in the list of schemas at the bottom.
This is what this endpoint expects in the request body.

The schema for ProductListViewModel is the schema used for the response.

Try with something like this:

{
    "PageSize":5,
    "CurrentPage":1,
    "ShowPricesWithVat":true,
    "Parameters" : { "MainProductID":"PROD105" }
}

/Morten

 

Votes for this answer: 1
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Morten and Morten,

 

WIth both your replies I was able to get it, so thank you very much.

 

Yes, it was confusing to make sense of some of this. It's mostly on my lack of knowledge and experience, but now I understand what needs to be submitted in the querystring vs in the body with this endpoint.

 

I am unblocked and can do my refactoring.

 

Thanks a lot.

Nuno Aguiar

 

You must be logged in to post in the forum