Square Connect API V2 ListCustomers返回不全,如何获取全部客户?
解决Square Connect API V2获取全部客户的问题
你碰到的这个情况确实是Square API的默认行为——ListCustomers接口默认只返回商户主动创建的客户,而Square通过交易、POS系统等自动生成的客户记录(也就是你说的“Square创建”类)不会被包含在默认结果里,这就是为什么你后台能看到8k客户但接口只返回151个的原因。
要获取所有客户(包括Square创建的),只需要在调用list_customers时添加include_profiles_created_by_square=True参数即可。修改后的代码如下:
def get_customers(api, cursor=None): customers = {} count = 0 while cursor or count == 0: # 新增参数以包含Square创建的客户 response = api.list_customers(cursor=cursor, include_profiles_created_by_square=True) cursor = response.cursor customers[count] = response.customers count += 1 return customers
这个参数的默认值是False,开启后接口会返回所有类型的客户档案,同时分页游标也会正常生成,直到你遍历完所有8k条客户数据。
如果调用时遇到参数不被识别的情况,建议检查下你使用的Square SDK版本是否过旧,更新到最新版即可解决。
内容的提问来源于stack exchange,提问作者sulimmesh
相关产品推荐
相关产品推荐

