如果你正在使用Lengow的订单API检索订单,请确保遵循我们的最佳使用建议:
身份验证令牌
由"access/get_token"返回的会话令牌的有效期为一小时。你不应该在每次请求之前请求令牌;否则,你可能会触及速率限制并在你的请求中被阻止。
要找出令牌剩余的时间,你可以使用api /me,它提供了当前令牌的过期时间。
示例:
curl --request GET \
--url 'https://api.lengow.io/me' \
--header 'Authorization: 69946b78-edae-49b8-8874-6fb025e09a58'
{
"token": "69946b78-edae-49b8-8874-6fb025e09a58",
"expire_at": "2022-12-21T13:56:08+00:00",
"account_id": 1,
"scopes": {
"feed_id": "*",
"account_id": 1,
"catalog_id": "*",
"product_id": "*"
}
}
订单检索
订单列表API具有可以实现多种补充方法的 筛选。
查找新订单
"merchant_order_id=None"筛选参数只会返回"merchant_order_id"为空的订单。
你也可以限制搜索期限以加快查询速度(例如,最后三个小时)。
示例:
curl --request GET \
--url 'https://api.lengow.io/v3.0/orders/?account_id=1&merchant_order_id=None&marketplace_order_date_from=2022-12-21T12%3A22%2B01%3A00' \
--header 'Authorization: 69946b78-edae-49b8-8874-6fb025e09a58'
然后,每个订单都可以使用moi API(= 商户订单id - 参考我们的API文档)标记为"已看到",并使用特定于商户的标识符。因此,标记的订单将在下一次查询中缺失。
搜索更新
订单有一个"updated_at"字区分,只要订单的任何信息发生变化,该字区分就会更新。
这个日期可以用来检索更新的订单,通过使用"updated_from"和"updated_to"进行筛选。
示例:
curl --request GET \
--url 'https://api.lengow.io/v3.0/orders/?account_id=1&updated_from=2022-12-21T14%3A22%2B01%3A00&updated_to=2022-12-21T15%3A22%2B01%3A00' \
--header 'Authorization: 69946b78-edae-49b8-8874-6fb025e09a58'
分页
命令列表最多分页为100。
如果有额外的页面可用,JSON内容中的"next"键包含下一页的URL。
否则,"next"键是null,这意味着当前页面是最后一页。
因此,请确保只有当"next"不是null时才查询下一页。
避免简单地迭代页面编号,直到你得到一个404(未找到)页面,这就是当你请求超出现有页面时会发生的情况。
更重要的是,避免迭代有限数量的页面,这会增加导致404错误的无用请求。
下一页URL包含在"next"键中的示例:
{
"count": 4481,
"next": "https://api.lengow.io/v3.0/orders/?account_id=1&merchant_order_id=None&page=2",
"previous": null,
"results": [
[...]
对订单的操作
订单操作是异步处理的。发送状态更新会创建一个任务,该任务被排队,然后由一个单独的进程处理。
API调用的响应返回任务标识符,然后可以用来获取任务的状态和结果。
已处理的订单操作的示例:
curl --request GET \
--url 'https://api.lengow.io/v3.0/orders/actions/?account_id=1&id=81982959' \
--header 'Authorization: 69946b78-edae-49b8-8874-6fb025e09a58'
"results": [
{
"id": 81982959,
"marketplace_order_id": "221219V2102418423",
"account_id": 1,
"marketplace": "veepee_pink_fr",
"action_type": "ship",
"processed": true,
"queued": false,
"tracking_number": "8G48609462340",
"tracking_url": "https://www.laposte.fr/outils/suivre-vos-envois?code=8G48609462340",
"carrier": "La Poste",
[...]
"created_at": "2022-12-21T11:17:47.353491Z",
"updated_at": "2022-12-21T11:17:48.408401Z",
[...]
}
]
你可以使用"queued"和"processed"字区分跟踪每个操作的状态:
- "queued"在操作等待处理(或在失败时重试)时为"true",在处理时为"false";
- "processed"在操作成功时为"true"。
与其单独搜索过去的操作,不如只检索那些需要处理的操作更有效。
在以下示例中,我们正在寻找未成功的Veepee操作:
curl --request GET \
--url 'https://api.lengow.io/v3.0/orders/actions/?account_id=1&marketplace=veepee_pink_fr&processecurl -X GET 'https://api.lengow.io/api/v3.0/orders/actions/?account_id=1&marketplace=veepee_pink_fr&page=1&processed=False&queued=False' \
--header 'Authorization: 69946b78-edae-49b8-8874-6fb025e09a58'
{
"count": 16778,
"next": "https://api.lengow.io/api/v3.0/orders/actions/?account_id=1&marketplace=veepee_pink_fr&page=2&processed=False&queued=False",
"previous": null,
"results": [
{
"id": 81428959,
"marketplace_order_id": "221211V1101346433",
"account_id": 223,
"marketplace": "veepee_pink_fr",
"action_type": "ship",
"processed": false,
"queued": false,
[...]
"errors": "超过速率限制。",
注意:答案像命令列表一样进行分页,使用“next”来跟踪下一页。
市场API
由市场API提供的数据变化很小。
因此,每小时请求一次就足够了,甚至更少。