Accessing Product Variant Data via APA

John Bratteli asked on January 19, 2017 18:58

I've got a product with hundreds of variants. I'm tracking inventory by variant, but I'd like to give the customer availability feedback when they select the variant options, as opposed to when they Add to Cart. I'm working on an AJAX solution that should access the REST API. I've got a couple of issues, but I'll stick to one for now.

What class do I need to access to get the variant inventory? I thought it would be CMS.Product, but /rest/cms.product/all (yes, I'm working with global admin while building this) gives me a 404 error.

I'll note that I'm successfully accessing the REST API with AJAX elsewhere on the site.

Correct Answer

John Bratteli answered on January 20, 2017 15:16

While didn't help directly, it did tell me that the service does some self-documenting, if you just access /rest. That's how I found that the name to use to get products is ecommerce.sku. Also, while they're in the same table in the DB, we need to use ecommerce.skuvariant in the service request. So, my request to get all the variants of a product with a given ID worked out to be /rest/ecommerce.skuvariant?format=json&where=SKUParentSKUID=34

0 votesVote for this answer Unmark Correct answer

Recent Answers

Trevor Fayas answered on January 19, 2017 19:22 (last edited on January 19, 2017 19:24)

Product Variations are also cms.sku objects, just with a "SKUParentSKUID" not as null (if it's a number, then that ID is the SKUID of it's parent)

So just look for /rest/com.sku/all and try to find the variant sku information in there, you can also access that object's SKUAvailableItems to get the inventory.

Likewise, if this gets a bit difficult, you can always use a Custom Query Repeater to query the SKU with some URL Parameters, Transforming it into a JSON object, and then use the Webpart to API converter to convert it to a JSON feed. That's how i do my APIs and i never have to touch code.

0 votesVote for this answer Mark as a Correct answer

John Bratteli answered on January 19, 2017 20:28

Thanks, Trevor, for help with what I just realized is an embarrassingly-titled question. I might look into the converter in a bit, but I'd like to figure out what I'm doing wrong with the API if I can. Both /rest/com.sku/all and /rest/cms.sku/all both return 404 errors. Thoughts?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.