Rest API to add owners has stopped working

I used to use the rest api to update the owners of groups. This now seems to have stopped working (though the groups definitely exist):

Method: PUT, RequestUri: 'https://forums.mysite.uk/admin/groups/1949/owners', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Api-Key: <redacted>
  Api-Username: admin
  Accept: application/json
  User-Agent: BasecampGatewayLive
  Content-Type: application/x-www-form-urlencoded
}:{
  "group": {
    "usernames": "kay"
  }
}
StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: nginx/1.22.1
  Date: Thu, 23 Jan 2025 02:03:44 GMT
  Transfer-Encoding: chunked
  Connection: keep-alive
  Vary: Accept-Encoding
  Vary: Accept
  X-Request-ID: 8e5dcf66-c4e0-4d4f-a382-dacb774691c3
  X-Runtime: 0.004369
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  Content-Type: application/json; charset=utf-8
}
{"errors":["The requested URL or resource could not be found."],"error_type":"not_found"}

This used to work fine, but a Discourse upgrade seems to have broken it. As this api is not included in the Discourse API page, I’m not sure how to find out what has changed.

Many endpoints aren’t documented, but you can Reverse engineer the Discourse API easily.

For me, the request works on the latest Discourse version:

My guess is that your API key is no longer valid.

I thought about that, but an invalid key or username normally returns a 403, not a 404 :person_shrugging:

I found the issue:

The correct URL is https://forums.mysite.uk/groups/1949/owners, without the /admin/.

2 Likes

You’ll also want to tell the server you’re sending json, not a form.

3 Likes