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

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
]
}
]
}

Related

Item level tracking in Shopify

Could you please specify, what is the correct way to track the quantity of the variants of items in stock?
I see that products/update webhook shows the quantity, but I'm not sure if it fires when an item is purchased (and its quantity reduces by one), and in case of inventory_items/update there's no quantity information (though it seems I can thract it using InventoryLevel API call), but I'm not sure if this notification launches after item purchase.
Short answer: Both products/update and inventory_levels/update are fired when an item is purchased.
The request body of products/update looks something like this:
{
"id": 123,
"variants": [
{
"id": 456,
"product_id": 123,
"inventory_quantity": 99
}
]
}
inventory_quantity is the updated stock of the item that has just been purchased.
On the other hand, the request body of inventory_levels/update looks something like this:
{
"inventory_item_id": 987,
"available": 99
}
So both webhook topics give you access to the data you need. In the end it depends on your specific use case which of those two topics to use.

Square Connect API: Retrieving all items within a category

I have been reading over the Square Connect API and messing around with the catalog portion.
I am unable to find how to retrieve all items and their data associated with a particular category. Can someone please point me in the right direction.
I thought it was the
BatchRetrieveCatalogObjects endpoint
I was using the category ID but it was only returning the catalog's data. I need each of the IDs of the items to retrieve their individual data.
I was looking to propagate a list of all the items and their data in one request in JSON.
JSON data to be passed to endpoint:
data = {
"object_ids": [
"category id"
],
"include_related_objects": True
}
My connection to the API:
category_item_endpoint = self.connection.post('/v2/catalog/batch-retrieve', data)
I am using python3 and the requests library.
In order to list items in a category I found it easiest to use the /v2/catalog/search endpoint. Simply follow the documentation on what parameters are accepted. Below are the search parameters that I used to list items by category id.
let sParams: JSON = [
"object_types": [
"ITEM"
],
"include_related_objects": true,
"include_deleted_objects": false,
"query": [
"exact_query": [
"attribute_name": "category_id",
"attribute_value": id
]
],
"limit": 1000
]
You'd probably have the most luck listing your entire catalog GET /v2/catalog/list and then applying filtering (in this case specific catagory_ids ) after you get the data. Based on the documentation doing what you desire doesn't seem possible with an endpoint/query combitionation.

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.

Shopify Create Order API

I used the Shopify API to create an order using my product's variantID.
For some reason, line_items in orders created using the API always have "vendor":"null". Whereas orders for the same variant created via the store returns the correct vendor.
Am I doing anything wrong?
URL: https://xxyy.myshopify.com/admin/orders.json
{ "order": {
"email": "ken#xxyy.com",
"fulfillment_status": "unfulfilled" ,
"send_receipt": true,
"send_fulfillment_receipt": false,
"line_items": [{
"variant_id": 3866750123,
"quantity": 1
}]
}
}
I get that sometimes too and it is truly crappy. If you create a line item using the API it seems you need to provide not only the product and variant ID, but also the vendor, as even if it exists in the product, that does not get picked up in the order creation process. A lot of Apps screw this up. Which screws up other Apps expecting good orders. And a it seems to me a good order should have the product vendor field set.

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

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.