shopify插件开发的问题记录

简介

Shopify作为流行的电商平台,支持安装各种插件扩展功能
插件开发中难免会遇到各种问题,记录和跟踪这些问题非常重要
emmmm…之前遇到过一些问题,但时间有点长记得不清楚了… …
这里先记录一些最近遇到的,之后再不断补充

商家卸载/重新安装token会改变

不要使用token作为商家的唯一标识符, token会在商家卸载重装之后发生改变.
可以使用shop的Id作为唯一标识符, 这个是不变的.
并且记得用户重新安装之后更新token.

相关api: https://shopify.dev/docs/api/admin-rest/2023-07/resources/shop

admin api获取商品分页问题

相关api: Products > Product > Retrieve a list of products

这个api提供了一个sinceId和limit的参数,看着就是用于分页的.

since_id
Return only products after the specified ID.

limit ≤ 250 default 50
Return up to this many results per page.

但这里有个细节文档没写, 如果你第一次不传sinceId=0,那么返回的list不是按照id排序的!
他会按照title排序导致第二次的分页结果是错误的.
因为这个带有一定的随机性, 而且数据本身是正常返回的, 可能不太容易发现这个问题.

社区里问这个的挺多的:
Rest Api Pagination With Since_id

官方博客里也有:
How to Use Relative Pagination In Your Application

To ensure the first page is sorted by id, you can include a since_id parameter with a value of 0. This form of pagination already existed on all endpoints prior to the 2019-07 API version.

应该是当成一个默认已知的约定了吧…