I am using eBay’s new REST Sell API to create an inventory item. I am having problems creating product aspects manually. I’ve tried creating a list of name value pairs but eBay is returning the following error:
Could not serialize field [product.aspects]
Below is the request payload sample from eBay:
{
"availability": {
"shipToLocationAvailability": {
"quantity": 50
}
},
"condition": "NEW",
"product": {
"title": "GoPro Hero4 Helmet Cam",
"description": "New GoPro Hero4 Helmet Cam. Unopened box.",
"aspects": {
"Brand": [
"GoPro"
],
"Type": [
"Helmet/Action"
],
"Storage Type": [
"Removable"
],
"Recording Definition": [
"High Definition"
],
"Media Format": [
"Flash Drive (SSD)"
],
"Optical Zoom": [
"10x"
]
},
"imageUrls": [
"http://i.ebayimg.com/images/i/182196556219-0-1/s-l1000.jpg",
"http://i.ebayimg.com/images/i/182196556219-0-1/s-l1001.jpg",
"http://i.ebayimg.com/images/i/182196556219-0-1/s-l1002.jpg"
]
}
}
As far as I know product aspects are not fixed and can be anything, because of this I cannot create a Class. I’m not sure how to handle this apart from manually creating the JSON and inserting it in the correct place in the request payload.
Is there a better way to do this? Maybe create a dynamic object on the fly (any examples would help)?
2
Answers
I ended up creating a list of an Aspect object, using an extension method to manually convert the list into JSON which I deserialize into an object and pass into the request payload to eBay.
I ended up modifying the OpenAPI contract to make this work.
The Aspect is a
System.Collections.Generic.ICollection<string>
which will never serialize into the correct JSON, whatever you put in there. I changed it to adynamic
type.Then to add to the Aspects, this is my code:
This could possibly be done a bit neater, but this is working and uploads to eBay correctly.