Webhook Fails with WP Discourse Plugin

I’ve installed the WP Discourse Plugin and everything seems to be working fine except the “Sync Comment Data” webhook. It keeps coming back as Failed with a Status Code: 400.

This is the response:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
  • The payload URL seems to be correct.
  • Webhook Secret Key is set in both discourse and the WP plugin.
  • Content Type is application/json
  • Post Event is checked
  • Check TLS certificate of payload url is checked
  • Active is checked

Any thoughts would be greatly appreciated

2 Likes

Double check that the payload URL and Webhook Secret Key are set correctly.

If that doesn’t fix the issue, can you let me know what permalink structure your WordPress site is using? The permalink structure is found on the Settings / Permalinks section of your WordPress dashboard.

1 Like

payload url and webhook secret key are set correctly.

Permalink structure is Post Name

1 Like

What response do you get from your WordPress site if you click the “Ping” button from the webhook’s event list on Discourse?

2 Likes

1 Like

Just wondering if there are any further thoughts on this …

Do you know if you have disabled the WordPress Rest API on your site? If so, that would cause the webhook requests sent from Discourse to fail.

Seems to be enabled but I’ll look into it more

REST seems ok … but when I type the Payload URL into the browser I get a 404 …

That is expected, The route that the webhook posts to on Discourse only accepts a POST request.

Would the ping be expected to work then?

Yes, the ping should work.

What is the form of the URL you are adding to the webhook’s Payload URL field on Discourse? You can leave off the domain part of the URL. The URL that is given to you in the Sync Comment Data option’s description on WordPress should be correct (it is created based on the permalink structure that your site uses) but possibly it is wrong for your case.

https://my.url.net/wp-json/wp-discourse/v1/update-topic-content

Copy and paste from the WP Discoure plugin. Sync Comment Data section on the webhooks tab.

1 Like

The Payload URL looks correct. Do you have any security related plugins on your WordPress site that could be blocking the request?

We do now but we didn’t when I initially encountered the problem.

The plugin is WordPress Security Plugin | iThemes Security Pro

One of the advertised features of the Ithemes Security plugin is that it can be used to block access to the Rest API. It would be worth confirming that this isn’t the cause of the issue.

You don’t need to use the Sync Comment Data webhook with the WP Discourse plugin. The main benefit of using it is that it allows comments to show up immediately after they are posted on Discourse instead of having to wait up to 10 minutes to fetch new comments. On very busy sites, the webhook can reduce the number of API requests that your site is making to Discourse. This mainly affects sites that display comment numbers on a post index page.

Yes, I have it working but I wanted to implement the webhooks to avoid the delay.
I checked with our developer and he said there’s no REST API blocking before he installed the security plugin or after. I’m baffled.

Is there a way to confirm the payload URL other than on the discourse plugin webhook page?

The screenshot you posted above is a good indication that the payload URL is correct. The 400 response code that you are getting indicates that the WordPress server is rejecting the request. If the issue was a mismatched secret key, you would be getting a 500 response code.

If you have access to your WordPress site’s Access Log file, it would probably show you exactly what the problem is.

Are you familiar with the exact WP access log I should be looking at? I can’t find anything useful.