Developer forum

Forum » Development » Serialization error on product API endpoint (/dwapi/ecommerce/products/{id})

Serialization error on product API endpoint (/dwapi/ecommerce/products/{id})

David Mercer-Taylor
Reply

When trying to query the products endpoint by ID (ex: /dwapi/ecommerce/products/PROD560), I consistently get the following error. Has anyone seen this before? This is on 9.12.0.0, we have a default currency set in the backend so I don't think this is _actually_ an issue with resolving that value, not really sure where else to look.
 

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
  "ExceptionType": "System.InvalidOperationException",
  "StackTrace": null,
  "InnerException": {
    "Message": "An error has occurred.",
    "ExceptionMessage": "Error getting value from 'Price' on 'Dynamicweb.Ecommerce.ProductCatalog.ProductViewModel'.",
    "ExceptionType": "Newtonsoft.Json.JsonSerializationException",
    "StackTrace": "   at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n   at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n   at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n   at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()",
    "InnerException": {
      "Message": "An error has occurred.",
      "ExceptionMessage": "Value cannot be null.\r\nParameter name: key",
      "ExceptionType": "System.ArgumentNullException",
      "StackTrace": "   at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)\r\n   at Dynamicweb.Caching.DictionaryCache`2.GetCacheResult(IEnumerable`1 keys)\r\n   at Dynamicweb.Caching.ServiceCache`2.GetCache(IEnumerable`1 keys)\r\n   at Dynamicweb.Caching.ServiceCache`2.GetCache(TKey key)\r\n   at Dynamicweb.Ecommerce.ProductCatalog.ViewSettingsBaseCurrencyBase`1.GetCurrency()\r\n   at Dynamicweb.Ecommerce.ProductCatalog.ViewSettingsBaseCurrencyBase`1.GetPriceContext()\r\n   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass0_1.<BulkCreateView>b__34()\r\n   at System.Lazy`1.CreateValue()\r\n   at System.Lazy`1.LazyInitValue()\r\n   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass0_2.<BulkCreateView>b__37()\r\n   at System.Lazy`1.CreateValue()\r\n   at System.Lazy`1.LazyInitValue()\r\n   at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass0_2.<BulkCreateView>b__38()\r\n   at System.Lazy`1.CreateValue()\r\n   at System.Lazy`1.LazyInitValue()\r\n   at GetPrice(Object )\r\n   at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)"
    }
  }
}

Replies

 
David Mercer-Taylor
Reply

It seems like we can get around this by specifying the currency code and country code in every request. Is there a way to set a default value for those? It appears to not be using the default value from Settings > Ecommerce > Currencies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi David

Yes, some of the endpoints have had some issues with not using default currency and country if not specified as part of the request. We should have fixed these in later versions of the web-api. 

Sorry about the inconvenience!

BR Nicolai

Votes for this answer: 1
 
David Mercer-Taylor
Reply

Thanks Nicolai

 

You must be logged in to post in the forum