gpt4 book ai didi

rest - Magento 2 - REST API - 嵌套 json 文件中的 searchCriteria

转载 作者:行者123 更新时间:2023-12-03 18:14:41 25 4
gpt4 key购买 nike

我想过滤掉所有带有特定 country_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"
)

它不起作用,因为 country_id位于嵌套实体中。

所以我尝试替换 country_id通过 billing_address[country_id]但它也不起作用。

最佳答案

用于搜索的默认 REST API 仅搜索 sales_order 中可用的列 table 。

您无法使用 country_id 进行搜索,你会得到一个类似 column not found 的错误。要使其工作,您必须自定义方法 getListmagento/module-sales/Model/OrderRepository.php通过创建自定义模块,或者您可以构建自定义 API 以根据 country_id 获取订单详细信息

正确的网址

 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>

关于rest - Magento 2 - REST API - 嵌套 json 文件中的 searchCriteria,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48572726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com