Magento 2-REST API-嵌套json文件中的搜索条件
我想筛选出具有特定Magento 2-REST API-嵌套json文件中的搜索条件,rest,api,magento,magento2,Rest,Api,Magento,Magento2,我想筛选出具有特定国家/地区id的所有订单 下面是来自json响应的示例: { "items": [{ "total_qty_ordered": 3, "updated_at": "2018-01-10 15:59:05", "weight": 0, "billing_address": { "city": "Schaffhausen", "country_id":
国家/地区id的所有订单
下面是来自json
响应的示例:
{
"items": [{
"total_qty_ordered": 3,
"updated_at": "2018-01-10 15:59:05",
"weight": 0,
"billing_address": {
"city": "Schaffhausen",
"country_id": "CH"
}
}]
}
以下是我尝试过的:
url = (
"http://<host>/rest/V1/orders"
"?searchCriteria[filter_groups][0][filters][0][field]=country_id"
"&searchCriteria[filter_groups][0][filters][0][value]=CH"
)
url=(
"http:///rest/V1/orders"
“?搜索条件[筛选组][0][筛选组][0][字段]=国家/地区id”
“&searchCriteria[filter_groups][0][filters][0][value]=CH”
)
它不起作用,因为country\u id
位于嵌套实体中
因此,我尝试用
账单地址[country\u id]
替换国家id
,但它也不起作用。这是搜索条件的json结构
{
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "attribute_name",
"value": [string|int|float],
"condition_type": [string]; optional
}
more entries
]
}
more entries
],
"current_page": [int] page number; optional
"page_size": [int] number of items on a page; optional
"sort_orders": [ optional
{
"field": "attribute_name",
"direction": [int] -1 or 1
}
more entries
]
}
}
用于搜索的默认REST API仅搜索
sales\u order
表中可用的列
您不能使用国家/地区id
进行搜索,您将得到一个错误,如“未找到列”。要使其工作,您必须自定义方法getList
magento/module sales/Model/OrderRepository.php
通过创建自定义模块,或者您可以构建自定义API来获取基于country\u id的订单详细信息
正确的URL
http:/host/index.php/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=country_id&searchCriteria[filter_groups][0][filters][0][value]=US&searchCriteria[filter_groups][0][filters][0][conditionType]=eq
方法:GET
标题:
Content-Type : application/json
Authorization : Bearer <TOKEN>
内容类型:应用程序/json
授权:持票人
虽然此代码可能会回答问题,但提供有关如何和/或为什么解决问题的附加上下文将提高答案的长期价值。您得到解决方案了吗?@RafiqulHasan没有找到解决方案