如何获取 Akeneo PIM API 搜索中的产品数量
How to get the count of products in Akeneo PIM API search
我是 Akeneo PIM 的新手 API,目前使用“获取”连接器通过 API 获取产品和类别信息。
我已经设法让访问工作正常,我可以根据过滤器取回产品信息,但我很难找出实际退回的产品数量。
根据 API 文档,有一个名为“with_count”的查询参数,如果设置为“true”,您可以在响应中看到产品计数。
我已在请求中将其设置为 true:
http://example.com/api/rest/v1/product-models?with_count=true&pagination_type=search_after&limit=1&search={"brand":[{"operator":"IN","value":["brand_fred_perry"]}],"department":[{"operator":"IN","value":["department_polo_shirts"]}]}
但我在回复中看不到它:
{
"_links":{
"self":{
"href":"http://example.com/api/rest/v1/product-models?with_count=true\u0026pagination_type=search_after\u0026limit=1\u0026search=%7B%22brand%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22brand_fred_perry%22%5D%7D%5D,%22department%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22department_polo_shirts%22%5D%7D%5D%7D"
},
"first":{
"href":"http://example.com/api/rest/v1/product-models?with_count=true\u0026pagination_type=search_after\u0026limit=1\u0026search=%7B%22brand%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22brand_fred_perry%22%5D%7D%5D,%22department%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22department_polo_shirts%22%5D%7D%5D%7D"
},
"next":{
"href":"http://example.com/api/rest/v1/product-models?with_count=true\u0026pagination_type=search_after\u0026limit=1\u0026search=%7B%22brand%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22brand_fred_perry%22%5D%7D%5D,%22department%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22department_polo_shirts%22%5D%7D%5D%7D\u0026search_after=qtTUjg%3D%3D"
}
},
"_embedded":{
"items":[
{
"_links":{
"self":{
"href":"http://example.com/api/rest/v1/product-models/aw19m3600106"
}
},
"code":"aw19m3600106",
"family":"default",
"family_variant":"default_size",
"parent":null,
"categories":[
"fred_perry_polo_shirts",
"fred_perry",
"polo_shirts"
],
"values":{
"brand":[
{
"locale":null,
"scope":null,
"data":"brand_fred_perry"
}
],
"color":[
{
"locale":null,
"scope":null,
"data":"color_burgundy"
}
],
"department":[
{
"locale":null,
"scope":null,
"data":"department_polo_shirts"
}
],
"name":[
{
"locale":null,
"scope":null,
"data":"Fred Perry M3600 Burgundy Polo Shirt"
}
]
},
"created":"2020-03-26T08:40:24+00:00",
"updated":"2020-03-26T08:40:24+00:00",
"associations":{
"PACK":{
"products":[
],
"product_models":[
],
"groups":[
]
},
"SUBSTITUTION":{
"products":[
],
"product_models":[
],
"groups":[
]
},
"UPSELL":{
"products":[
],
"product_models":[
],
"groups":[
]
},
"X_SELL":{
"products":[
],
"product_models":[
],
"groups":[
]
}
}
}
]
}
}
API 文档还说我应该在响应中看到“current_page”,但正如您在上面看到的那样,它不存在...
编辑
结果我把“pagination_type”设置为“search_after”时看不到它。
pagination_type
“search_after
”与参数 with_count
不兼容。
由于您不需要检索大量产品,您可以安全地使用“page
”pagination_type
或删除此参数,因为它是默认值,您应该会返回产品计数器。
api 文档部分对此进行了解释:https://api.akeneo.com/documentation/pagination.html
我是 Akeneo PIM 的新手 API,目前使用“获取”连接器通过 API 获取产品和类别信息。
我已经设法让访问工作正常,我可以根据过滤器取回产品信息,但我很难找出实际退回的产品数量。
根据 API 文档,有一个名为“with_count”的查询参数,如果设置为“true”,您可以在响应中看到产品计数。
我已在请求中将其设置为 true:
http://example.com/api/rest/v1/product-models?with_count=true&pagination_type=search_after&limit=1&search={"brand":[{"operator":"IN","value":["brand_fred_perry"]}],"department":[{"operator":"IN","value":["department_polo_shirts"]}]}
但我在回复中看不到它:
{
"_links":{
"self":{
"href":"http://example.com/api/rest/v1/product-models?with_count=true\u0026pagination_type=search_after\u0026limit=1\u0026search=%7B%22brand%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22brand_fred_perry%22%5D%7D%5D,%22department%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22department_polo_shirts%22%5D%7D%5D%7D"
},
"first":{
"href":"http://example.com/api/rest/v1/product-models?with_count=true\u0026pagination_type=search_after\u0026limit=1\u0026search=%7B%22brand%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22brand_fred_perry%22%5D%7D%5D,%22department%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22department_polo_shirts%22%5D%7D%5D%7D"
},
"next":{
"href":"http://example.com/api/rest/v1/product-models?with_count=true\u0026pagination_type=search_after\u0026limit=1\u0026search=%7B%22brand%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22brand_fred_perry%22%5D%7D%5D,%22department%22:%5B%7B%22operator%22:%22IN%22,%22value%22:%5B%22department_polo_shirts%22%5D%7D%5D%7D\u0026search_after=qtTUjg%3D%3D"
}
},
"_embedded":{
"items":[
{
"_links":{
"self":{
"href":"http://example.com/api/rest/v1/product-models/aw19m3600106"
}
},
"code":"aw19m3600106",
"family":"default",
"family_variant":"default_size",
"parent":null,
"categories":[
"fred_perry_polo_shirts",
"fred_perry",
"polo_shirts"
],
"values":{
"brand":[
{
"locale":null,
"scope":null,
"data":"brand_fred_perry"
}
],
"color":[
{
"locale":null,
"scope":null,
"data":"color_burgundy"
}
],
"department":[
{
"locale":null,
"scope":null,
"data":"department_polo_shirts"
}
],
"name":[
{
"locale":null,
"scope":null,
"data":"Fred Perry M3600 Burgundy Polo Shirt"
}
]
},
"created":"2020-03-26T08:40:24+00:00",
"updated":"2020-03-26T08:40:24+00:00",
"associations":{
"PACK":{
"products":[
],
"product_models":[
],
"groups":[
]
},
"SUBSTITUTION":{
"products":[
],
"product_models":[
],
"groups":[
]
},
"UPSELL":{
"products":[
],
"product_models":[
],
"groups":[
]
},
"X_SELL":{
"products":[
],
"product_models":[
],
"groups":[
]
}
}
}
]
}
}
API 文档还说我应该在响应中看到“current_page”,但正如您在上面看到的那样,它不存在...
编辑
结果我把“pagination_type”设置为“search_after”时看不到它。
pagination_type
“search_after
”与参数 with_count
不兼容。
由于您不需要检索大量产品,您可以安全地使用“page
”pagination_type
或删除此参数,因为它是默认值,您应该会返回产品计数器。
api 文档部分对此进行了解释:https://api.akeneo.com/documentation/pagination.html