【问题标题】:easybill REST Api Increase Limit Dataeasybill REST Api 增加限制数据
【发布时间】:2020-12-19 14:55:36
【问题描述】:

不幸的是,我还有一个关于 easybill 的 REST API 的问题 :-(

链接:https://www.easybill.de/api/ 或:https://api.easybill.de/rest/v1/swagger.json

我希望你能读懂我的英文。我使用谷歌翻译。

我的问题是我最多只能查询 100 个客户数据。

在 Api 互联网页面上它说,“所有结果列表默认限制为 100。此限制可以通过查询参数限制增加到最大 1000。”

但我在互联网上找不到任何关于如何在我的代码中增加此限制的帮助。

我希望你能帮助我。

这是我的代码:

$url = "https://api.easybill.de/rest/v1/customers";
$ch = curl_init();
$accesstoken = "XXXXXXX";
$headr = array();
$headr[] = 'Content-length: 0';

$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: Bearer '.$accesstoken;

curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result=curl_exec($ch);
curl_close($ch);

$data = json_decode($result,true);
$users=$data;

print '<pre>';
print_r($users);
print '</pre>';

来自德国的问候

【问题讨论】:

  • 你好,参考easybill.de/api它声明“所有结果列表默认限制为100。此限制可以通过查询参数限制增加到最大1000。”所以只需将 , ?limit=1000 附加到您的 $url

标签: php json rest


【解决方案1】:

查询字符串表示参数属于url,对于GET,它是传递任何参数的唯一选项。

所以你在它后面加上'?'与网址分开。

https://api.easybill.de/rest/v1/customers 得到https://api.easybill.de/rest/v1/customers?limit=1000

但这不是解决问题的最佳方法。如果有 1001 位客户,您将永远不会收到最后一位。

根据文档,还有一个page 参数。所以最好发送多个请求并增加页码。

所以调用这些 url,直到你不会得到任何数据:

https://api.easybill.de/rest/v1/customers?page=1
https://api.easybill.de/rest/v1/customers?page=2
https://api.easybill.de/rest/v1/customers?page=3
...

【讨论】:

猜你喜欢
  • 2020-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-11
  • 1970-01-01
  • 2021-11-22
相关资源
最近更新 更多