Shopify API - 创建webhook(批量请求)

时间:2018-01-18 16:13:11

标签: php api request shopify webhooks

我已经设法使用Shopify API创建了webhook,但我每个请求只能创建一个webhook。我已经尝试自定义请求,因此它可能会立即创建一些webhook,但它似乎不起作用。

我正在使用GuzzleHttp \ Client来处理我的请求,这就是我的工作请求:

$client = new Client();
$response = $client->request(
'POST',
"https://{$store}/admin/webhooks.json",
[
    'headers' => [
        'X-Shopify-Access-Token' => $access_token,
        'X-Shopify-Shop-Domain' => $store
    ],
    'form_params' => [
        'webhook' => [
            "topic" => "orders/create",
            "address" => $appAddress,
            "format" => "json"
        ],
    ]
]);

但是当我尝试这样的事情时:

$client = new Client();
$response = $client->request(
'POST',
"https://{$store}/admin/webhooks.json",
[
    'headers' => [
        'X-Shopify-Access-Token' => $access_token,
        'X-Shopify-Shop-Domain' => $store
    ],
    'form_params' => [
        'webhook' => [
            [
                "topic" => "orders/create",
                "address" => $appAddress,
                "format" => "json"
            ],
            [
                "topic" => "orders/delete",
                "address" => $appAddress,
                "format" => "json"
            ]
        ]
    ]
]);

我得到了这个:

POST https://smshopify.myshopify.com/admin/webhooks.json导致了 422 Unprocessable Entity响应:{“errors”:{“topic”:[“不能为空”,“指定的主题无效。允许的主题:app / uninstalled, carts / create,carts / u(截断...)

有没有办法在一个请求中创建几个webhooks,我在Shopify文档中找不到关于它的单词,我修改请求主体的尝试不是很成功。我设法做的只是预测主题数组和每个webhook的单个请求。

1 个答案:

答案 0 :(得分:2)

不,没有办法在一个请求中创建一批webhook。大多数Shopify资源都是如此 - 例如产品也必须一个接一个地创建。