c# - 如何在 Orderhive API 中获取所有产品
问题描述
我正在使用 Orderhive 新版本的 API -> https://orderhive.docs.apiary.io/#reference/product/product-catalog。根据文档,可以在 URL 中添加大小,但是当我尝试这个时,我遇到了错误的请求错误。
我在下面尝试了这些,所有这些都相同的错误“错误请求”:
https://api.orderhive.com/product/listing/flat?size=500
https://api.orderhive.com/product/listing/flat?size=1000&page=1
试过这个,它正在工作但是我只能得到 20 个产品 https://api.orderhive.com/product/listing/flat
如何查询到下一页?
谢谢你。
解决方案
如https://orderhive.docs.apiary.io/#reference/product/product-catalog/product-catalog中所述
default
size
为 20,最大尺寸为 1000
C# 中的示例调用如下所示。您可以根据需要更改 URI & StringContent
in content 作为参数:
//Common testing requirement. If you are consuming an API in a sandbox/test region, uncomment this line of code ONLY for non production uses.
//System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
//Be sure to run "Install-Package Microsoft.Net.Http" from your nuget command line.
using System;
using System.Net.Http;
var baseAddress = new Uri("https://private-anon-c49488141a-orderhive.apiary-mock.com/");
using (var httpClient = new HttpClient{ BaseAddress = baseAddress })
{
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "AWS Signature Headers(check in above Authentication flow)");
using (var content = new StringContent("{ \"types\": [ \"7\", \"1\" ], \"qty_ranges\": [ { \"min\": \"1\", \"max\": \"2\", \"warehouse_id\": \"\", \"key\": \"available_qty\" } ], \"date_ranges\": [ { \"min\": \"1560760921\", \"max\": \"1560769921\", \"key\": \"modified\" } ], \"query\": \"nike\"}"))
{
using (var response = await httpClient.PostAsync("product/listing/flat?size=500", content))
{
string responseData = await response.Content.ReadAsStringAsync();
}
}
}
推荐阅读
- php - 2 个日期之间不包括第一天
- android - 谷歌登录游戏失败
- python - Pyomo:使用列表参数化约束
- python - 如何将函数定义为其他函数及其相关参数的总和并拟合参数 [python]
- laravel - auth()->user() 在功能测试时在 ServiceProvider 中返回 null
- javascript - 在 jQuery 中创建的元素不会触发侦听器
- android - EmojiCompat 动态列出表情符号
- swift - 当我在 swiftUI 中打开 TabView 的视图时,onReceive 不执行
- regex - 除了在 perl 中将每个单词放在单独的行上之外,尝试输入格式化的文本文件并删除所有空格
- sql - 查询具有 30 秒时间窗口的运行平均值,向前移动 5 秒