Webhook not working

I’m testing webhooks - Ghost and a node.js client both on localhost

Client tested - is OK:
curl -X POST http://localhost:3000/api/active/0
-H “Content-Type: application/json”
-d ‘{“event”:“test”}’

Response: {“data”:{“event”:“test”},“isActive”:“0”}

DEBUG=ghost:services:webhooks node current/index.js

[2025-06-10 13:33:58] INFO Triggering webhook for “page.unpublished” with url “http://localhost:3000/api/active/0
[2025-06-10 13:33:58] INFO [Webmention] Sending all webmentions for http://localhost:2368/p/
[2025-06-10 13:33:58] WARN Request to http://localhost:3000/api/active/0 failed because of: ECONNREFUSED.

Why ECONNREFUSED?
Because of “localhost”?

Thanks for help
Joe

Yes, it’s related to localhost. ECONNREFUSED means the server rejected the connection. You might need to switch to using 127.0.0.1 instead of localhost because newer versions of node might resolve localhost to ::1 on linux-based systems

2 Likes

You were right - with 127.0.0.1 it works!
Thank you!

But possible a bug - webhook is not triggered when I run “Unpublish”

Only works if I edit the page and the click on the button “Unpublish”.

It looks like you set up a “Page unpublished” webhook, but you’re unpublishing a post

No, I unpublishing a page. But I can “Copy a link to post”.

Bulk actions from the post list do not trigger webhooks. If you want to to run, you need to unpublish from within the post itself. (@vikaspotluri123 there’s some discussion over on github if you’re curious.)

Lol I initially added “it could also be a bug in the Admin that’s labelling a page as a post” but I removed it because that was obviously a red herring :upside_down_face:

Why is this a bulk action? I do “unpublish” always for a single post.
It’s the same for me as “unpublish from within the post”.

Making any changes using the right-click menu is considered a bulk action, even if you select a single post. If you go to the post editor and click the unpublish button at the top-right of the page, that’s not a bulk action, and you should see the webhook delivered

It is easier to do it via the right mouse menu.
It makes no difference to me whether you do it this way or that.
The webhook should always be triggered.
So I always have to think for myself …

Agreed! That’s why I have an issue open on it.

I can push my WIP branch over to Github in case anyone wants to pick it up. I haven’t had time. [Edit: That assumes I can find my WIP branch. What the heck did I do???]

1 Like