Wordpress Webhook 401 error

AI-generated summary

Wordpress Webhook 401 error

nash4ever encountered a 401 Unauthorized error when calling their Wordpress endpoints using webhooks, displaying a “This server could not verify that you are authorized to access the document requested” error message.

simon asked if nash4ever was using the wp-discourse plugin, which they confirmed. nash4ever also noted that their X-Discourse-Instance header was set to http, which they couldn’t change, although they had set the Discourse URL to https in their WP settings.

simon suggested enabling the ‘force https’ setting on Discourse, which nash4ever did, resulting in the X-Discourse-Instance header being sent as https. However, the error persisted.

simon asked about the webhook payload URL and Wordpress version, to which nash4ever replied that their payload URL was set correctly and they were using Wordpress 4.9.3.

Ultimately, nash4ever discovered that the issue was on their side, as they had set HTTP authentication on the site due to it not being public, and apologized for wasting simon’s time.

Hi,
I would like to use webhooks but when I call my endpoints I get this error:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<hr>

Headers

Server: Apache/2.4.18 (Ubuntu)
WWW-Authenticate: Basic realm="Restricted Content"
Content-Length: 466
Connection: close
Content-Type: text/html; charset=iso-8859-1

Do you have any idea what is the problem?

Thanks for your help.

Are you using the wp-discourse plugin, or are these endpoints that you have added yourself?

I’m using the official wp-discourse plugin.
What I see int he Webhook log that my

X-Discourse-Instance: http://forum.example.com

and I set Discourse URL to https://forum.example.com on the WP settings page.

FYI: if it can be an issue, then I could not change the X-Discourse-Instance to https, I don’t know where can I change it.

Have you enabled the ‘force https’ setting on Discourse?

No, but I chaged it after your post and the error is the same, but now I’m sending:

X-Discourse-Instance: https://forum.example.com

in the header

Is the webhook payload URL set to https://yoursite.com/wp-json/wp-discourse/v1/update-topic-content ?

What version of WordPress are you using?

There might be some ideas on this page that can help: Authorization Errors with Wordpress API - Justin D Johnson

Our Payload URL:
https://example.com/wp-json/wp-discourse/v1/update-topic-content

What version of WordPress are you using?

WordPress 4.9.3

Thanks for all of your help, the problem was on my side, I forgot that I set http authentication on the site because it is not public.
I apologize for wasting your time.