在 ShopifyAPI::Order.All 中包含已履行的订单

问题描述 投票:0回答:1

作为我的 Shopify 应用程序的一部分,我想保留我的每一个订单的本地导出。我有一个 ruby 脚本,可以实现我在这里需要的大部分功能,但它只获取未履行的订单。

我尝试通过添加这样的参数来调整 ShopifyAPI::Order.all

fullfilled_orders=ShopifyAPI::Order.all(params: { status: 'any',fulfillment_status: 'fulfilled'})

我尝试对这两个字段使用“any”和“fulfilled”的变体,甚至不带参数运行它,但输出保持不变。

应用程序在商店的设置页面拥有所有可能的权限,并且 ruby 中的应用程序范围设置为这样

范围:'read_all_orders read_orders read_customers read_users',

这是该函数的片段

def order_dl()
    # Load API credentials from file
    config = YAML.load_file('config.yml')


    # Shopify API credentials
    session = ShopifyAPI::Auth::Session.new(
    shop: config['shop'],
    access_token: config['access_token'],
    )

    ShopifyAPI::Context.setup(
    api_key: config['api_key'],
    api_secret_key: config['api_secret_key'],
    api_version: '2024-01', # Example: '2024-01'
    scope: 'read_all_orders read_orders read_customers read_users',
    is_private: false, # Set to true if you are using a private app
    is_embedded: true # Set to true if you are using an embedded app
    )

    ShopifyAPI::Context.activate_session(session)

    client = ShopifyAPI::Clients::Rest::Admin.new(
    session: session
    )
    test_session = ShopifyAPI::Context.active_session


    #retrieve order details
    orders = ShopifyAPI::Order.all(params: { status: 'any', fulfillment_status: 'any'})
    infos=[]
ruby shopify shopify-app
1个回答
0
投票

您似乎错误地传递了选项。根据 docs

status
fulfillment_status
是关键字参数,应按如下方式传递:

ShopifyAPI::Order.all( status: 'any', fulfillment_status: 'any')

请注意,默认情况下,这只会检索前 50 个。 API 文档

您可以使用

limit: 250
将限制设置为 250;但是,您一次无法检索超过 250 条记录,因此要真正接收所有记录,您可能必须使用
since
updated_at_min

等偏移量多次循环此过程
© www.soinside.com 2019 - 2024. All rights reserved.