How to find Shopware 6 total record count for a list endpoint

I have set up an incoming configuration for Product Manufactures from Shopware 6 (using the list endpoint …/api/product-manufacturer). I have set up pagination for this and all works fine. Only, how or where can I see the total of Manufacturers in there, as a total number or number of pages given my limit? This would be needed to estimate scheduling as to how often and how many at a time we should run through, and to know the job is done before I start to run through the products in the same manner. Grateful for any answers!

Edit: I found Shopware documentation which shows that meta.total key should have that value, but in the data I have got in my Alumio response that value is just the total of records in the page.

Hi Kjetil,

I believe that Shopware provides you with a links object. This object should contain the a link to the next, previous, first and last page. You can use the Follow pagination functionality of the HTTP subscriber to let Alumio automatically retrieve subsequent pages.

Assuming you don’t have too many product manufacturers, you could let Alumio pull all pages with each execution.

1 Like

Yes, there is a links object as well. But as with the meta.total the links.last is not in there. I will try and see if there is something to be configured on the Shopware side. The Manufacturers are not som many, but products are - and there is the same case.
I tried for the sake of testing to pull all manufacturers in one go without pagination but that resulted in a timeout or resource error.

@kjetil can you share your request & response?

Blockquote ```
{
“data”: [
{
“id”: “00695776de3b488b81537f00192e0b2f”,
“type”: “product_manufacturer”,
“attributes”: {
“versionId”: “0fa91ce3e96a4bc2be4bd9ce752c3425”,
“mediaId”: null,
“link”: “”,
“name”: “To-Go Ware”,
“description”: “”,
“customFields”: null,
“createdAt”: “2023-01-07T16:38:05.000+00:00”,
“updatedAt”: “2023-01-07T16:38:05.000+00:00”,
“translated”: {
“name”: “To-Go Ware”,
“description”: “”,
“customFields”: {}
},
“apiAlias”: null
},
“links”: {
“self”: “…/api/product-manufacturer/00695776de3b488b81537f00192e0b2f”
},
“relationships”: {
“media”: {
“data”: null,
“links”: {
“related”: “…/api/product-manufacturer/00695776de3b488b81537f00192e0b2f/media”
}
},
“products”: {
“data”: ,
“links”: {
“related”: “…/api/product-manufacturer/00695776de3b488b81537f00192e0b2f/products”
}
},
“translations”: {
“data”: ,
“links”: {
“related”: “…/api/product-manufacturer/00695776de3b488b81537f00192e0b2f/translations”
}
}
},
“meta”: null
}
],
“included”: ,
“links”: {
“first”: “…/api/product-manufacturer?limit=1&page=1”,
“next”: “…/api/product-manufacturer?limit=1&page=2”,
“self”: “…/api/product-manufacturer?limit=1”
},
“meta”: {
“totalCountMode”: 0,
“total”: 1
},
“aggregations”:
}


for request: GET /api/product-manufacturer?limit=1 HTTP/1.1

I just found the solution for getting the total (in this thread: Paging not working correctly through @shopware-pwa/shopware-6-client (or REST) · Issue #2313 · shopware/platform · GitHub). Shopware doc here.

For Shopware it’s needed to add the total-count-mode 1 in the query object of the request:
{
“path”: ,
“query”: {
“limit”: 1,
“total-count-mode”: 1
},
“payload”:
}

Now the response include this:

  "links": {
    "first": ".../api/product-manufacturer?limit=1&total-count-mode=1&page=1",
    "last": ".../api/product-manufacturer?limit=1&total-count-mode=1&page=264",
    "next": ".../api/product-manufacturer?limit=1&total-count-mode=1&page=2",
    "self": ".../api/product-manufacturer?limit=1&total-count-mode=1"
  },
  "meta": {
    "totalCountMode": 1,
    "total": 264
  },

Now I would like to add that total-count to the Pagination Storage I have for this Incoming request - or maybe to its own storage.

@kjetil you can use the ‘Save entity to storage’ transformer on the incoming configuration to store the meta.total field to the storage. Then you can use the ‘Input transformer’ on the incoming configuration with the Get an entity from storage transformer to retrieve said value for the next request.

I made such a transformer but unfortunately it did not work out. The response in the incoming is boiled down {“meta”:{}, “data”:} . The data object is an array containing the items. Applied pagination and said ‘data’ to be the items (stored in storage and later sent to outgoing). In the end of the incoming config (after pagination) I added the save entity to storage for meta and links object. BUT at that point the entity seems to no more include what’s outside of the data object. I only get links and meta object that are inside data object.
When I run the test on the full response I get the expected objects stored to storage. But I don’t see a place to put this transformer before the item entity “clipping” is done. However this is not a show-stopper. I probably don’t need to bother about the totals in advance (just me like to know I got all there was). And I guess one workaround would be to make a separate call (Incoming) with limit 1, page 1 and don’t process for items just to get the total and store that without any outgoing.

@kjetil if you use the pagination option on the HTTP subscriber it will indeed change to scope to the underlying items. This means you are indeed unable to access the meta key on the root. For now there you’ll need to rely on workarounds in case you want to store it.