How to retrieve all products from a Smart Collection through Shopify API? - shopify

What's the best way to retrieve all products from a Smart Collection through Shopify API?
Thanks!

Update: API version 2020-04
See Codesmith's answer below. As of API version 2020-04, you can now use a smart collection id with the collections endpoint:
GET /admin/api/2020-04/collections/{collection_id}/products.json
See the Collection API docs for more info.
Pre-2020 solution
From the SmartCollection page in the Shopify API docs:
Smart Collections also use collects to connect a product to that smart collection.
And on the Collects page:
List only collects for a certain collection
GET /admin/collects.json?collection_id=841564295
HTTP/1.1 200 OK
{
"collects": [
{
"collection_id": 841564295,
"created_at": "2014-05-23T14:16:47-04:00",
"featured": false,
"id": 1071559648,
"product_id": 921728736,
"sort_value": "0000000001",
"updated_at": "2014-05-23T14:16:47-04:00",
"position": 1
},
...
]
}
The collects contain the product_ids for each of the products in the collection with the specified collection_id.

2020 Update,
For the latest API (2020-04 as of now), you can simply use the /collections/ endpoint, using the Smart Collection ID:
GET https://<shopname>.myshopify.com/admin/api/2020-04/collections/<smart collection id>/products.json
More details can be found in Shopify's Collection API Docs.

Related

How to get the products in a category thats based on Dynamic Product Groups from the shopware API

I have a high volume shop with a lot of products and categories.
The products are seasonal, so a lot of new products are added.
Because of this, dynamic product groups are perfect. We set conditions and add the group to the category.
Right now i'm trying to get all the products of the category in the api's (both backend and store), but i dont get any product back. I do get a streamId back in the store-api https://localhost//store-api/product-listing/9cf2c65bd7084144aa4d4a35bb3f568e But there is no endpoint i can call for the streamId.
Next to that, the breadcrumbs are also missing on the front-end.
What is the best way to get a the products from a category back in the API?
Thanks!
If you do have the id of the product_stream you can filter product entities by them having that id as part of their streamIds:
// POST /api/search-ids/product
{
"page": 1,
"limit": 500,
"filter": [
{
"type": "equalsAny",
"field": "streamIds",
"value": [
"65103ca79e1e4e3ba846f551fbb1cb36" // your product stream id
]
}
]
}

Whats the most RESTFul way to add resources?

For example, if there is a rest api for a shop system to add articles to my shopping cart without knowing the id, what would be the most restful way to design the url to call and what about the serverside implementation? I know there is some flexibility when designing rest apis, but what is "state of the art"?
Lets say my database does have the table "articles", "shoppingcarts", "article_pos".
articles (id, article_name, price, color),
shoppingcarts (id, description),
article_pos (id, shoppingcart_id, article_id)
Example to create an article:
POST "/api/shop/article/"
Request:
{
"article_name": "table",
"price": "100.00",
"color": "brown"
}
Example to get an existing article:
GET "/api/shop/article/4711"
Response:
{
"id": "4711",
"article_name": "table",
"price": "100.00",
"color": "brown"
}
But how I should design the url if I want to add article "4711" to the shopping cart?
Like this?
POST "/api/shop/shoppingcart/addArticle/4711?amount=1"
or Like this?
POST "/api/shop/article_pos/"
Request:
{
"shoppingcart_id": "1",
"article_id": "4711"
}
And how to get the article ID if a client doesn't know the ID (4711) but the articlename (table)?
But how I should design the url if I want to add article "4711" to the shopping cart?
POST /api/shop/shoppingcart/addArticleById/{4711}
fetch article details from article table, get the amount.
update shopping cart with these details
how to get article ID if a client doesn't know the ID (4711) but the articlename (table)?
POST /api/shop/shoppingcart/addArticleByName/{table}
fetch article details from article table, get the amount.
update shopping cart with these details
State Of the Art:
indentify resource by ID only, and use it for creating, updating details.
REST -> deals with resource first, hence a resource is first class citizen identified by a Id.

Fetching only shipped orders from orocommerce using API

I want to fetch orders with the internal status shipped from my orocommerce store what will be filter for that.In documentation I am not getting any help.
Thanks
Utpal Maity
Seems entity InternalStatus is disabled by default – https://github.com/oroinc/orocommerce/blob/master/src/Oro/Bundle/OrderBundle/Resources/config/oro/api.yml#L37.
If you change (overwrite in your api.yml) it to:
Extend\Entity\EV_Order_Internal_Status: ~
it will be available in API in relationships section:
"internal_status": ▿{
"data": {
"type": "orderinternalstatuses",
"id": "open"
}
}
}
as well as in filter. For other entities same configuration should be applied.
Please have a look at API documentation – https://github.com/laboro/dev/blob/f2a40c66127531287b4f0d5a35ed7800196be6ac/package/platform/src/Oro/Bundle/ApiBundle/Resources/doc/configuration.md

Access Product Variant Price with Stencil

With the legacy API, I can obtain product variant prices for productId 100 with the following:
https://something.com/api/v2/products/100/skus.json
But in the Stencil documentation for Product, there is no price property for a product attribute SKU, and the available properties that are available are limited vs the legacy API.
With product:
"values": [
{
"label": "Hardcover",
"id": 98,
"data": "Hardcover",
"selected": false
},
{
"label": "Paperback",
"id": 100,
"data": "Paperback",
"selected": false
}
],
From what I can gather, the variant pricing is only available via cart.items, but I need to display the prices before the user places an item in the cart.
Is there a way to get product variant pricing/info without using the cart.items object? Thanks!
I'm not aware of a way to do this via a stencil object.
On the product detail page I check if a product has_options, then make ajax calls to the variant URLs to get their prices to create a price range before the user selects their variants. This is pretty necessary when the vendor has huge price differences in variants.
ex.) "From $49.99 - $499.99" instead of "$49.99" default functionality.
I don't have a resolution for category pages as it doesn't make sense to make AJAX requests for each variant of each item on the category page on load. Once Stencil adds support for custom fields on the category page, you could add the child's prices to a parent SKUs custom field and perform some logic for whatever your trying to accomplish.
I don't know when custom fields will be available on the category page but I know they are working on it.

Office365 REST v1.0 API How to query global category list

I am using the new Office365 REST API: https://msdn.microsoft.com/en-us/office/office365/api/api-catalog and am successfully querying calendar events, which include their categories as a list of strings: https://outlook.office365.com/api/v1.0/me/events
How do I query the global list of all categories associated with a calendar, as well as the colour associated with each category? The colours I setup via the Outlook client appear to persist across client instances, and yet I can't find a way to access these data via the API.
Great question! You can't access that information currently with the REST APIs, but it's a great idea.
If you're curious, all the gory details on how the category list is stored are documented in [MS-OXOCFG].
You can actually do this now with the current version of the Graph API. If you want to list the categories that have been defined for a user, you can use either of these endpoints:
GET /me/outlook/masterCategories
GET /users/{id|userPrincipalName}/outlook/masterCategories
and get something like this:
HTTP/1.1 200 OK
Content-type: application/json
Content-length: 727
{
"#odata.context":"https://graph.microsoft.com/beta/$metadata#users('8ae6f565-0d7f-4ead-853e-7db94c912a1f')/outlook/masterCategories",
"value":[
{
"id":"5a9a6aa8-b65f-4357-b1f9-60c6bf6330d8",
"displayName":"Red category",
"color":"preset0"
},
{
"id":"4b1c2495-54c9-4a5e-90a2-0ab0b31987d8",
"displayName":"Orange category",
"color":"preset1"
},
{
"id":"de912e4d-c790-4da9-949c-ccd933aaa0f7",
"displayName":"Yellow category",
"color":"preset3"
}
]
}