首页 > 解决方案 > 如何在 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 在此处输入图像描述

如何查询到下一页?

谢谢你。

标签: c#restapiasp.net-mvc-4

解决方案


https://orderhive.docs.apiary.io/#reference/product/product-catalog/product-catalog中所述

default size为 20,最大尺寸为 1000

C# 中的示例调用如下所示。您可以根据需要更改 URI & StringContentin 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();
          }
      }
    }

推荐阅读