ruby-on-railsspree

Rails Spree API with multistore


As far as I know I can use three types of api with Spree. I only take the products as example.

  1. http://127.0.0.1:3000/api/products
  2. http://127.0.0.1:3000/api/v1/products
  3. http://127.0.0.1:3000/api/v2/products

I don't see any differences in the response between above 3 apis. It is so confusing.

Another confusion is when it comes to multi store Spree site, there is another version of api 4. http://127.0.0.1:3000/api/v2/storefront/products It returns the products only registered in current storefront.

Suppose I want to retrieve the products which belongs to other stores? Some suggests to use store_id=<store_id> parameter but it doesn't work at all.

And how can I get the store where the products belong to from the 1-3 api result. Anybody can help?

I use these spree versions, which I don't think much related to the issue. gem 'spree', '3.7.2' gem 'spree_gateway', '3.7.4' gem 'spree_core', '3.7.2' gem 'spree_api', '3.7.2'


Solution

  • With Spree 4.2 Multi-Store support is out of the box. Each store has its own URL which you set in Admin Panel UI, eg.

    1. Store A: canada.example.com
    2. Store B: europe.example.com

    So if you want to query products from Store A you need to use:

    https://canada.example.com/api/v2/storefront/products
    

    More on this: