Developer forum

Forum » Ecommerce - Standard features » Ecommerce web API

Ecommerce web API

Lars Larsen
Lars Larsen
Reply

Hi

I am trying to use the Ecommerce web API. But I can't get it to work. If for example I request this url:

/dwapi/Products/GetProductList?ProductIds=PROD213,PROD214&LanguageId=LANG1&CurrencyCode=DKK&FilledProperties=Id,VariantId,Name

I get this error message:

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>Some property names do not match the viewmodel ('Dynamicweb.Ecommerce.ProductCatalog.ProductListViewModel'): Invalid input=[Id, VariantId, Name], Valid property names=[Group, SubGroups, Products, PageSize, PageCount, CurrentPage, TotalProductsCount, SpellCheckerSuggestions, FacetGroups].</ExceptionMessage>
<ExceptionType>System.ArgumentException</ExceptionType>
<StackTrace> at Dynamicweb.Ecommerce.ProductCatalog.ViewSettingsBase`1.CheckInvalidNames() at Dynamicweb.Ecommerce.ProductCatalog.ViewSettingsBase`1.EnsureFilledPropertiesExist() at Dynamicweb.Ecommerce.ProductCatalog.ProductListViewModelSettings.EnsureFilledPropertiesExist() at Dynamicweb.Ecommerce.WebAPI.Controllers.ProductController.GetProductList(String[] productIds, ProductListViewModelSettings settings) at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()</StackTrace>
</Error>
 

If I request this url:

/dwapi/Products/GetProductGroupList/GROUP5?LanguageId=LANG1&CurrencyCode=DKK&FilledProperties=Id,VariantId,LanguageId,Name,ShortDescription,Number

I get this error message:

<Error>
<Message>No HTTP resource was found that matches the request URI 'http://[mysitename]/dwapi/Products/GetProductGroupList/GROUP5?LanguageId=LANG1&CurrencyCode=DKK&FilledProperties=Id,VariantId,LanguageId,Name,ShortDescription,Number'.</Message>
<MessageDetail>No action was found on the controller 'Product' that matches the request.</MessageDetail>
</Error>
 

Runnig DW v9.8.8


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Ok - 2 things is wrong (yes, the docs are completely of...!)

First I removed the FilledProperties parameter from your URL. That exposed another exception - a missing country.

So try to add &CountryCode=DK to set the country (and not CountryID as the docs say)

That will give you an output: See example from Rapido: http://rapidodemo.dynamicweb-cms.com/dwapi/Products/GetProductList?ProductIds=PROD133,PROD134&LanguageId=LANG1&CurrencyCode=DKK&CountryCode=DK

Then the other issue with the FilledProperties parameter. Each api call returns a viewmodel - this endpoint returns a ProductListViewModel and only properties available on that Viewmodel can be used on this parameter (See https://doc.dynamicweb.com/api/html/331be5f6-e3ef-f481-dcc3-c28656117247.htm)

But then the ProductListViewModel also has a list of products - and that is ProductViewModel - this one: https://doc.dynamicweb.com/api/html/49438f4d-3e3e-e636-d371-6070461fb7d5.htm

That is the one that your three properties is coming from: Id,VariantId,Name

To target those, you need to use a parameter for the sub viewmodel - so in this case, instead of FilledProperties=Id,VariantId,Name, it has to be &ProductSettings.FilledProperties=Id,VariantId,Name

It will look like this:

http://rapidodemo.dynamicweb-cms.com/dwapi/Products/GetProductList?ProductIds=PROD136,PROD137&LanguageId=LANG1&CurrencyCode=DKK&CountryCode=DK&ProductSettings.FilledProperties=Id,VariantId,Name

And then - you can also add FilledProperties= and add any property from the ProductListViewModel, i.e. FilledProperties=TotalProductsCount,Products

We will have a look at the docs. And add some null checks...

Votes for this answer: 1
 
Lars Larsen
Lars Larsen
Reply

Hi Nicolai

Thanks for clarification. But what about this endpoint: /dwapi/Products/GetProductGroupList

I can't get that to work either. Could you eleborate on that one too?

Btw. some of the property names are case sensitive eg. "Manufacturer". If this property is all lower case you get an error!

 
Mafalda Correa
Mafalda Correa
Reply

Hi Nicolai,

I'm trying to get a product list too and I was following this example. But then I also need the Price properties of the Products and I can't get that to work:

https://dev-swiftrizzo.mydwsite1.com/dwapi/Products/GetProductList
?ProductIds=10091,10154,10001
&LanguageId=LANG1
&CurrencyCode=DKK
&CountryCode=DK
&ShopId=SHOP1
&ProductSettings.FilledProperties=Id,VariantId,Name,Price
&ProductSettings.PriceSettings.FilledProperties=Price

I'm using this at the moment, but I get an error:

<ExceptionMessage>Error getting value from 'Price' on 'Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel'.</ExceptionMessage>

Can you guide me in what I might be doing wrong?

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Mafalda,

The error contains information about an inner exception (what caused the error)...

<InnerException>
<Message>An error has occurred.</Message>
<ExceptionMessage>No valid SMTP host found. Please specify a valid SMTP host in Control Panel. Errors: smtpmailtrap.io: System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtpmailtrap.io' at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at Dynamicweb.Mailing.EmailHandler.SendUsingSmptProtocol(MailMessage mailMessage, SmtpSender sender, List`1 hostList) </ExceptionMessage>
<ExceptionType>System.Exception</ExceptionType>
<StackTrace> at Dynamicweb.Mailing.EmailHandler.SendUsingSmptProtocol(MailMessage mailMessage, SmtpSender sender, List`1 hostList) at Dynamicweb.Mailing.EmailHandler.TryToSendEmail(MailMessage mailMessage, Boolean isFirstError, Boolean wasSent, List`1 hostList, ILogger systemSMTPLogger, SmtpSender sender) at Dynamicweb.Mailing.EmailHandler.Send(MailMessage mailMessage, Boolean logging, Boolean throwException, String username, String password, Int32 port, Boolean useSsl, String host) at Dynamicweb.Mailing.EmailHandler.Send(MailMessage mailMessage, Boolean logging, Boolean throwException) at Dna.Ecommerce.LiveIntegration.Logging.Logger.SendMail(String message) at Dna.Ecommerce.LiveIntegration.Logging.Logger.SendLog(String lastError, Boolean isLastErrorInLog) at Dna.Ecommerce.LiveIntegration.Logging.Logger.Log(LogType errorLevel, String logLine) at Dna.Ecommerce.LiveIntegration.Configuration.Global.get_IsIntegrationEnabledForShop() at Dna.Ecommerce.LiveIntegration.PrepareProductInfoProvider.PreparePrices(ProductCollection products) at Dynamicweb.Ecommerce.Prices.PriceManager.PreparePrices(IEnumerable`1 products) at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.PreparePrices(Boolean& pricesHasBeenPrepared, Object lock, IList`1 products) at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass0_2.<BulkCreateView>b__35() at System.Lazy`1.CreateValue() at System.Lazy`1.LazyInitValue() at GetPrice(Object ) at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)</StackTrace>
</InnerException>

It looks like you have a custom live integration which tries to send an email when PreparePrices is called, but the configured smtp host was unreachable. Maybe the configured smtp host should be smtp.mailtrap.io instead of smtpmailtrap.io? Go to Settings > Web and HTTP > SMTP and make sure the configuration is correct.

Best regards,
Morten

 
Mafalda Correa
Mafalda Correa
Reply

Well, now I feel silly. Thanks, fixing the SMPT hostname did it.

 

You must be logged in to post in the forum