Webhooks subscription throwing error

Highlighted
Shopify Partner
10 0 2

I am having the exact same problem as you are. 

 

Followed the tutorial... successfully registered webhooks. But ngrok keeps giving me a 405 method not allowed on my webhook routes. 

 

Uninstalling and reinstalling the app had no effect - still 405. 

 

I'm not as familiar with koa-router, I normally just use express... I can see the line:

server.use(router.allowedMethods());

But we're not setting that anywhere, does it just infer the allowed methods based on what routes have been configured by the router?

Or does this have to do with a configuration of ngrok?

Thanks in advance.

2 Likes
Highlighted
Excursionist
17 0 4

I'm having same problem, exact same server.js as example, everything works properly including registering the webhook, yet when I create a product ngrok is displaying:

 

POST /webhooks/products/create                                 403 Forbidden                    

POST //webhooks/products/create                                405 Method Not Allowed           

 

Removing and reinstalling isn't fixing it. I'm also occasionally seeing the following errors in my node app. 

 

Error: write EPIPE

      at afterWriteDispatched (internal/stream_base_commons.js:149:25)

      at writeGeneric (internal/stream_base_commons.js:140:3)

      at Socket._writeGeneric (net.js:776:11)

      at Socket._write (net.js:788:8)

      at doWrite (_stream_writable.js:435:12)

      at clearBuffer (_stream_writable.js:574:7)

      at Socket.Writable.uncork (_stream_writable.js:329:7)

      at connectionCorkNT (_http_outgoing.js:656:8)

      at processTicksAndRejections (internal/process/task_queues.js:81:21)

 

Also I'm running on MacOS Catalina, so I turned off the macos firewall, but didn't help.

0 Likes
Highlighted
Excursionist
17 0 4

OK, I found the problem. Registering the webhook using

 

const registration = await registerWebhook({
address:`${HOST}/webhooks/products/create`,
topic: 'PRODUCTS_CREATE',
accessToken,
shop,
apiVersion: ApiVersion.October19
});
 
 
while 
 
router.post('//webhooks/products/create', webhook, (ctx) => {
console.log('received webhook: ', ctx.state.webhook);
});
 
 
I knew that this code obviously works for everyone else, so I traced my mistake to misdeclaring host as:
 
1 Like
Highlighted
New Member
2 0 0

Thanks for the solution - that was driving me crazy. Kind of obvious after the fact. 

0 Likes
Highlighted
New Member
1 0 0

I'm having the same problem as well. I'm using the exact same file from the tutorial and my HOST is declared correctly. However, I'm still receiving the 405 forbidden method error on NGROK. I'm trying to receive a product creation webhook from the Shopify admin. I'm able to successfully register the webhook, but cannot receive it. Any other tips you might have?

0 Likes
Tourist
18 0 2

I came back to this project and now I used straight the code from github but its returning 405 when a webhook is fired. Ot works ok to register the webhook, but not to receive, neither from  the admin panel or when using a test shop to fire the events.

It seels to me that clearly the example on the github in this link does not work out of the box for receiving webhooks.
I`m gonna review this entire thing and see if I can post back a solution to when you start by the github example 

0 Likes
Highlighted
Excursionist
21 1 3

another "solution" for me was to remove the " " around the Host name in the process.env file.

and use the link https://XXXXXXXXXX.ngrok.io/auth?shop=XXXXXXXXXX.myshopify.com 

the webhook got registered properly;

event - compiled successfully
> Ready on http://localhost:3000
event - build page: /next/dist/pages/_error
wait  - compiling...
event - compiled successfully
Successfully registered webhook!
event - build page: /
wait  - compiling...
event - compiled successfully

but then the webhook is not visible in Setting - Notification and Ngrok has errors:

POST /                                                          405 Method Not Allowed   
POST /                                                          405 Method Not Allowed   
POST /                                                          405 Method Not Allowed   
GET  /_next/static/webpack/5b407d169f58e7464866.hot-update.json 200 OK                   
GET  /_next/webpack-hmr                                         200 OK                   
GET  /_next/webpack-hmr                                         200 OK                   
POST /graphql                                                   406 Not Acceptable   

and he UI has a network error:

Network error: Unexpected end of JSON input
0 Likes
Highlighted
Excursionist
21 1 3

got the solution from @Echizen  and it was what I was strongly looking after, the API version.

fixed the issue by changing the API version in the server.js file.

original mentions  server.use(graphQLProxy({ version: ApiVersion.April19 }));

changed to  server.use(graphQLProxy({ version: ApiVersion.April20 }));

if you are trying this and it s 2021, you should adapt the value as well..

suggestion, would be cool to have the API version as a .env setting..

0 Likes