3

I am trying to make an api call to get a list of products. I am using searchCriteria to filter the products collection. The following information of the product is needed:

-sku, name, id, price, status, visibility, type_id, qty, image-url, small-image-url

The following call gives all information, excluding qty:

http://127.0.0.1/rest/V1/products/?searchCriteria[filter_groups][0][filters][0][field]=price&searchCriteria[filter_groups][0][filters][0][value]=25&searchCriteria[filter_groups][0][filters][0][condition_type]=from&searchCriteria[filter_groups][0][filters][1][field]=price&searchCriteria[filter_groups][0][filters][1][value]=500&searchCriteria[filter_groups][0][filters][1][condition_type]=to&searchCriteria[pageSize]=2&searchCriteria[currentPage]=1

{
"items": [
 {
 "id": 1,
 "sku": "Test",
 "name": "Test 100x100",
 "attribute_set_id": 4,
 "price": 200,
 "status": 1,
 "visibility": 4,
 "type_id": "simple",
 "created_at": "2017-08-23 17:48:05",
 "updated_at": "2017-08-23 17:48:05",
 "weight": 1,
 "extension_attributes": [],
 "product_links": [],
 "tier_prices": [],
 "custom_attributes": [
 {
 "attribute_code": "meta_title",
 "value": "Test"
 },
 {
 "attribute_code": "meta_keyword",
 "value": "Test"
 },
 {
 "attribute_code": "meta_description",
 "value": "Test "
 },
 {
 "attribute_code": "image",
 "value": "/c/a/cat1.png"
 },
 {
 "attribute_code": "small_image",
 "value": "/c/a/cat1.png"
 },
 {
 "attribute_code": "thumbnail",
 "value": "/c/a/cat1.png"
 },
 {
 "attribute_code": "options_container",
 "value": "container2"
 },
 {
 "attribute_code": "required_options",
 "value": "0"
 },
 {
 "attribute_code": "has_options",
 "value": "0"
 },
 {
 "attribute_code": "url_key",
 "value": "test"
 },
 {
 "attribute_code": "swatch_image",
 "value": "/c/a/cat1.png"
 },
 {
 "attribute_code": "tax_class_id",
 "value": "2"
 },
 {
 "attribute_code": "gift_message_available",
 "value": "2"
 },
 {
 "attribute_code": "laenge_intern",
 "value": "100.0000"
 },
 {
 "attribute_code": "breite_intern",
 "value": "100.0000"
 },
 {
 "attribute_code": "sw_featured",
 "value": "0"
 }
 ]
 },
 {
 "id": 2,
 "sku": "Test-1",
 "name": "Test 100x110",
 "attribute_set_id": 4,
 "price": 200,
 "status": 1,
 "visibility": 4,
 "type_id": "simple",
 "created_at": "2017-08-29 20:20:54",
 "updated_at": "2017-08-29 20:20:54",
 "weight": 1,
 "extension_attributes": [],
 "product_links": [],
 "tier_prices": [],
 "custom_attributes": [
 {
 "attribute_code": "meta_title",
 "value": "Test"
 },
 {
 "attribute_code": "meta_keyword",
 "value": "Test"
 },
 {
 "attribute_code": "meta_description",
 "value": "Test "
 },
 {
 "attribute_code": "image",
 "value": "/c/a/cat1_1.png"
 },
 {
 "attribute_code": "small_image",
 "value": "/c/a/cat1_1.png"
 },
 {
 "attribute_code": "thumbnail",
 "value": "/c/a/cat1_1.png"
 },
 {
 "attribute_code": "options_container",
 "value": "container2"
 },
 {
 "attribute_code": "required_options",
 "value": "0"
 },
 {
 "attribute_code": "has_options",
 "value": "0"
 },
 {
 "attribute_code": "url_key",
 "value": "test-1"
 },
 {
 "attribute_code": "swatch_image",
 "value": "/c/a/cat1_1.png"
 },
 {
 "attribute_code": "tax_class_id",
 "value": "2"
 },
 {
 "attribute_code": "gift_message_available",
 "value": "2"
 },
 {
 "attribute_code": "laenge_intern",
 "value": "100.0000"
 },
 {
 "attribute_code": "breite_intern",
 "value": "110.0000"
 },
 {
 "attribute_code": "sw_featured",
 "value": "0"
 }
 ]
 }
],
"search_criteria": {
 "filter_groups": [
 {
 "filters": [
 {
 "field": "price",
 "value": "25",
 "condition_type": "from"
 },
 {
 "field": "price",
 "value": "500",
 "condition_type": "to"
 }
 ]
 }
 ],
 "page_size": 2,
 "current_page": 1
},
"total_count": 6
}

In the Doc Site http://devdocs.magento.com/guides/v2.1/howdoi/webapi/filter-response.html they mention the 'fields' parameter to get the items qty. I tried the following call, but it still does not include qty into the response:

http://127.0.0.1/rest/V1/products/?searchCriteria[filter_groups][0][filters][0][field]=price&searchCriteria[filter_groups][0][filters][0][value]=25&searchCriteria[filter_groups][0][filters][0][condition_type]=from&searchCriteria[filter_groups][0][filters][1][field]=price&searchCriteria[filter_groups][0][filters][1][value]=500&searchCriteria[filter_groups][0][filters][1][condition_type]=to&searchCriteria[pageSize]=2&searchCriteria[currentPage]=1 &fields=items[id,sku,name,qty]

As expected it returns items with id, sku, name. But no qty.

How to get item qty in the response ?

Thanks

asked Sep 4, 2017 at 18:28
0

2 Answers 2

1

In my response I found qty in extension_attributes.

"extension_attributes": {
 "stock_item": {
 "item_id": 4876,
 "product_id": 4884,
 "stock_id": 1,
 "qty": 0,
 ...

If you use custom product type you need to add special config for product type (etc/product_types.xml).

isQty="true"

Example:

<type name="mySpecialType" label="MySpecialType Product" isQty="true" ...
answered Oct 25, 2017 at 17:33
0

The stock_item (including qty) is no longer included in a extension_attributes. It was deprecated a while ago (see issue #24418) though the REST documentation on Adobe's site still shows it included n the response from the /V1/products endpoint.

You can use this plugin to bring it back: https://github.com/menacoders/Stock-Info-API-searchCriteria

Or a simple (no code) plugin which adds a single "qty" field to the extension_attributes: https://github.com/cristoper/mage_qtyext

answered Oct 5, 2021 at 18:04
1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.