简体   繁体   English

通过 Rest API Magento 2 获取带有 id 的特定产品

[英]Get specific product with id via Rest API Magento 2

I want to get the information from an specific product.我想从特定产品中获取信息。

I am using this reference in this moment, and get all the products in given searchCriteria:我此时正在使用此参考,并获取给定搜索条件中的所有产品:

http://www.mysite.co/rest/V1/products-render-info?storeId=1&currencyCode=cop http://www.mysite.co/rest/V1/products-render-info?storeId=1&currencyCode=cop

Is there a way I can send the product id in the url and get only all its information?有没有办法可以在 url 中发送产品id并仅获取其所有信息?

You can add the filter您可以添加过滤器

http://www.mysite.co/rest/V1/products?searchCriteria[filterGroups][0][filters][0][field]=entity_id&searchCriteria[filterGroups][0][filters][0][value]=1&searchCriteria[filterGroups][0][filters][0][condition_type]=eq

use field entity_id instead of id , value is product id here 1 , condition_type is equal to here eq .使用字段entity_id而不是id ,这里的值是产品 id 1 , condition_type 等于这里的eq

You can fetch product info by SKU, not ID.您可以通过 SKU 而不是 ID 获取产品信息。

API endpoint (get method) will pull product info. API 端点(get 方法)将拉取产品信息。 vendor/magento/module-catalog/etc/webapi.xml

/V1/products/:sku

So, your rest API calling URL should be like this所以,你的 rest API 调用 URL 应该是这样的

http://www.mysite.co/rest/V1/products/productsku

Note: If you want to fetch product info by id, you probably need to create a simple rest API.注意:如果您想通过 id 获取产品信息,您可能需要创建一个简单的 rest API。 you can check this out.你可以看看这个。 https://magento.stackexchange.com/questions/282480/i-am-new-here-i-want-to-know-how-can-i-create-my-own-simple-api/282730 https://magento.stackexchange.com/questions/282480/i-am-new-here-i-want-to-know-how-can-i-create-my-own-simple-api/282730

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM