方形连接 api 批处理

square connect api batch processing

我需要批处理方面的帮助,尤其是在向项目添加税码方面。

我正在试验方形批处理功能,我的示例案例是创建 2 个项目并向它们添加税码。在所有 4 个请求中 - 2 个用于创建项目,2 个用于 'put' 税码。我尝试了以下命令: 1.创建两个项目;加税 2.创建一个项目;为该项目添加税码;创建第二个项目,将代码添加到第二个项目。

在这两种情况下,结果是相同的 - 税款仅适用于一件商品。对于第二项,我得到的响应是:

{
    "status_code":404,
    "body":{
        "type":"not_found",
        "message":"NotFound"
    },
    "request_id":4
}

为了帮助调查,这里是我在 cURL 请求中使用的示例 json。

{
"requests":[
    {
        "method":"POST",
        "relative_path":"\/v1\/me\/items",
        "access_token":"XXX-YYY",
        "body":
            {
                "id":126,
                "name":"TestItem",
                "description":"TestItemDescription",
                "category_id":"DF1F51FB-11D6-4232-B138-2ECE3D89D206",
                "variations":[
                    {
                        "name":"var1",
                        "pricing_type":"FIXED_PRICING",
                        "price_money":
                            {
                                "currency_code":"CAD",
                                "amount":400
                            },
                        "sku":"123444:QWEFASDERRG"
                    }
                ]},
        "request_id":1
    },
    {
        "method":"PUT",
        "relative_path":"\/v1\/me\/items\/126\/fees\/7F2D50D8-43C1-4518-8B8D-881CBA06C7AB",
        "access_token":"XXX-YYY",
        "request_id":2
    },
    {
        "method":"POST",
        "relative_path":"\/v1\/me\/items",
        "access_token":"XXX-YYY",
        "body":
            {
                "id":127,
                "name":"TestItem1",
                "description":"TestItemDescription1",
                "category_id":"DF1F51FB-11D6-4232-B138-2ECE3D89D206",
                "variations":[
                    {
                        "name":"var1",
                        "pricing_type":"FIXED_PRICING",
                        "price_money":
                            {
                                "currency_code":"CAD",
                                "amount":400
                            },
                        "sku":"123444:QWEFASDERRG1"
                    }
                ]
            },
        "request_id":3
    },
    {
        "method":"PUT",
        "relative_path":"\/v1\/me\/items\/127\/fees\/7F2D50D8-43C1-4518-8B8D-881CBA06C7AB",
        "access_token":"XXX-YYY",
        "request_id":4
    }
]
}

以下是我收到的完整回复,表明已成功创建两项,只有一项成功推送。

[
{
    "status_code":200,
    "body":
        {
            "visibility":"PUBLIC",
            "available_online":false,
            "available_for_pickup":false,
            "id":"126",
            "description":"TestItemDescription",
            "name":"TestItem",
            "category_id":"DF1F51FB-11D6-4232-B138-2ECE3D89D206",
            "category":
                {
                    "id":"DF1F51FB-11D6-4232-B138-2ECE3D89D206",
                    "name":"Writing Instruments"
                },
            "variations":[
                {
                    "pricing_type":"FIXED_PRICING",
                    "track_inventory":false,
                    "inventory_alert_type":"NONE",
                    "id":"4c70909b-90bd-4742-b772-e4fabe636557",
                    "name":"var1",
                    "price_money":
                        {
                            "currency_code":"CAD",
                            "amount":400
                        },
                    "sku":"123444:QWEFASDERRG",
                    "ordinal":1,
                    "item_id":"126"
                }
            ],
            "modifier_lists":[],
            "fees":[],
            "images":[]
        },
    "request_id":1
},
{
    "status_code":200,
    "body":{},
    "request_id":2
},
{
    "status_code":200,
    "body":
        {
            "visibility":"PUBLIC",
            "available_online":false,
            "available_for_pickup":false,
            "id":"127",
            "description":"TestItemDescription1",
            "name":"TestItem1",
            "category_id":"DF1F51FB-11D6-4232-B138-2ECE3D89D206",
            "category":
                {
                    "id":"DF1F51FB-11D6-4232-B138-2ECE3D89D206",
                    "name":"Writing Instruments"
                },
            "variations":[
                {
                    "pricing_type":"FIXED_PRICING",
                    "track_inventory":false,
                    "inventory_alert_type":"NONE",
                    "id":"6de8932f-603e-4cd9-99ad-67f6c7777ffd",
                    "name":"var1",
                    "price_money":
                        {
                            "currency_code":"CAD",
                            "amount":400
                        },
                    "sku":"123444:QWEFASDERRG1",
                    "ordinal":1,
                    "item_id":"127"
                }
            ],
            "modifier_lists":[],
            "fees":[],
            "images":[]
        },
    "request_id":3
},
{
    "status_code":404,
    "body":
        {
            "type":"not_found",
            "message":"NotFound"
        },
    "request_id":4
}
]

我已经检查了项目列表,并且两个项目及其项目 ID 都存在于库存中。所以我的问题是,为什么税收适用于一件物品而不适用于另一件物品?如何解决?

来自Square docs

Note the following when using the Submit Batch endpoint:

You cannot include more than 30 requests in a single batch.

Recursive requests to the Submit Batch endpoint are not allowed (i.e., none of the requests included in a batch can itself be a request to this endpoint).

There is no guarantee of the order in which batched requests are performed.

(强调我的)。

如果您想使用批次 API,您必须先创建项目等父实体,然后在单独的批次请求中应用任何子实体,如费用、折扣等...或者,您可以提出单独的请求。在这种情况下,使用批处理 API 可能没有太大好处。