Shopify返回“主题不能为空”的webhook POST,即使我正在提供一个

时间:2012-09-14 21:50:00

标签: shopify

我正在尝试创建一个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"]}}

我已经确认:

  • 主题的拼写正确
  • 根据docs
  • ,JSON请求有效负载正确地包装在“webhook”(单数)中
  • 我已将JSON复制并粘贴到jsonlint.com中,以便检查JSON是否有效

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

UPDATE :我通过传递Content-type: application/json标题让它在命令行上工作。但是现在我在PHP中遇到了curl_exec的问题。我有以下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)

请注意,我可以在curl上完成GET,只有POST返回这个令人困惑的回复。

1 个答案:

答案 0 :(得分: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。