我正在尝试在这里创建一个 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"]}}
我已经确认:
- 题目拼写正确
- 根据文档,JSON 请求有效负载正确地包装在“webhook”(单数)中
- 我已将 JSON 复制并粘贴到 jsonlint.com 以检查 JSON 是否有效
困惑...没有看到与此相关的任何其他问题,我一定是在做一些非常明显的错误 - 否则每个人都会遇到这个问题。
更新:我通过传入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 返回这个令人困惑的响应。