Why does webhook creation fail with a 400 Bad Request error?

Hi

Hopefully someone can help me. We are seeing an instance where a request to create a webhook for a particular shop fails with error 400 Bad Request. The identical request works fine on other Shopify shops though. We have a valid token and correct scopes.

Here’s a request to get the current webhooks for store - I’ve obfuscated the store

GET https://***.myshopify.com/admin/api/2023-07/webhooks.json

Request Headers “X-Shopify-Access-Token”:“*****”}

Response {“webhooks”:}}

Then we try to create a webhook

POST https://***.myshopify.com/admin/api/2023-07/webhooks.json

Request Headers {“X-Shopify-Access-Token”:“*****”,“Content-type”:“application/json”

Request Body {“webhook”:{“topic”:“orders/paid”,“address”:“https://new.tideconnects.com/public/shopify_sale/459”,“format”:“json”}}

HTTP Code 400

Response Headers: {“server”:“cloudflare”,“date”:“Fri, 19 Jan 2024 04:42:11 GMT”,“content-type”:“text/html”}

Response “\r\n400 Bad Request\r\n\r\n

400 Bad Request

\r\n
cloudflare\r\n\r\n\r\n”}

So it seems to be stopped by Cloudflare. I understand Shopify is protected by Cloudflare, but does anybody know why this request is being blocked? We are connected up to a few dozen Shopify Stores and we don’t see this error on any other stores.

I appreciate any help I can get on this one!

Steve

Hi,

I have got the similar issue about cloudfare.And my solution is VPN.Here is my situation:

  1. I am develping a shopify app and my IP is China mainland.

  2. A few days ago,I found our IP was blocked.And every server on China mainland is not working.

  3. And then, the remix server on local is not working.So we guessed the cloudfare may block the IP.

  4. So we have to use VPN to develop,and move our app to US cloud server.

  5. Everything is fine for now.

Hi

Thanks for replying. That’s interesting, but we can create webhooks OK for other shops so I don’t think our IP is blocked by Cloudflare.

Regards

Steve

So I found the issue and leaving this for anybody else facing a similar issue. It turned out that the store had multiple domains and we had been given an alias of the actual base domain. This allowed us to use the API but only for GET. POST calls generate a 400 bad request. Switching to the base domain as reported in the shop call myshopify_domain field allows POST and thus creation of webhooks.

Hey Steven Im also struggling to make POST requests work for ajax calls to my ProxyApp’s backend. You’re saying the value for myshopify_domain should replace everything before the proxy app’s subpath? For example myshopify_domain_value/apps/subpath

Hi

I’m not sure how this might work in a proxy situation. We are just directly accessing the REST and GraphQL APIs in shopify and found that if we did that via a shop alias, for example https://myshop.com/admin/api/2024-07/customer.json, then some of the API calls like webhooks woudn’t work. Replacing that with https://abcd.myshopify.com/api/2024-07/customer.json fixed the problem. The https://abcd.myshopify.com is returned in myshopify_domain via the Shops endpoint https://shopify.dev/docs/api/admin-rest/2024-07/resources/shop

Hope that helps

Steve

this was definitely insightful, but yeah I’ve only been working with app proxies so far. Its weird that my ajax set up was working fine last year, and suddenly now I haven’t managed to overcome the http 400 errors. Passing the Access Token and ensuring the Content-Type is application/json is apparently not enough.. thanks anyways!