1

我正在尝试在这里创建一个 webhook:

curl --header "X-Shopify-Access-Token: <token>" -d '{"webhook": {"topic": "orders/create", "address": "http://www.google.com/", "format": "json"}}' https://test-store-402.myshopify.com/admin/webhooks.json

这是为了便于阅读而漂亮打印的 JSON:

{
    "webhook": {
        "topic": "orders/create",
        "address": "http://www.google.com/",
        "format": "json"
    }
}

它返回此错误:

{"errors":{"topic":["can't be blank","Invalid topic specified. Topics allowed: orders/create, orders/updated, orders/paid, orders/cancelled, orders/fulfilled, orders/partially_fulfilled, app/uninstalled, customer_groups/create, customer_groups/update, customer_groups/delete, products/create, products/update, products/delete, collections/create, collections/update, collections/delete, carts/create, carts/update"],"address":["can't be blank"]}}

我已经确认:

困惑...没有看到与此相关的任何其他问题,我一定是在做一些非常明显的错误 - 否则每个人都会遇到这个问题。

更新:我通过传入Content-type: application/json标题让它在命令行上工作。但是现在我curl_exec在 PHP 中遇到了问题。我有以下 CURLOPT 集:

CURLOPT_RETURNTRANSFER: true
CURLOPT_SSL_VERIFYPEER: false
CURLOPT_FOLLOWLOCATION: true
CURLOPT_MAXREDIRS: 10
CURLOPT_CUSTOMREQUEST: 'POST'
CURLOPT_HTTPHEADER: array {
    0 => string 'X-Shopify-Access-Token: <token>'
    1 => string 'Content-type: application-json' (length=30)

请注意,我可以做 GET 就好了curl- 只有 POST 返回这个令人困惑的响应。

4

1 回答 1

2

让它在 curl_exec 中工作。这是我正在使用的:

CURLOPT_RETURNTRANSFER: true
CURLOPT_SSL_VERIFYPEER: false
CURLOPT_FOLLOWLOCATION: true
CURLOPT_MAXREDIRS: 10
CURLOPT_CUSTOMREQUEST: 'POST'
CURLOPT_HTTPHEADER: array {
    0 => string 'X-Shopify-Access-Token: <token>'
    1 => string 'Content-type: application-json' (length=30)
CURLOPT_POSTDATA: '{"webhook":{"topic":"orders/updated","address":"http://www.google.com","format":"json"}}'

我认为问题可能是我在上面的更新中遗漏了 CURLOPT_POSTDATA 。

于 2012-09-14T23:07:18.477 回答