Hello Discourse Community,
I’m currently facing challenges with Discourse API endpoints, specifically related to suspending users, and would greatly appreciate any assistance or guidance you can offer.
Summary of Issues
-
404 Not Found:
- When using the endpoint:
/admin/users/15/suspend.json
, I consistently receive a “Page Not Found” error, even though the user exists. - I’ve also tried the alternative endpoint:
/admin/u/15/suspend.json
, which results in the same issue.
- When using the endpoint:
-
Unexpected HTML Response:
- Instead of returning the expected JSON response, the API returns an HTML page with the message:
“Oops! That page doesn’t exist or is private.” - This occurs regardless of whether I’m using
curl
or PowerShell for the request.
- Instead of returning the expected JSON response, the API returns an HTML page with the message:
-
API Key and Permissions:
- The API key being used has full admin access, yet the requests continue to return a
404
error. - I’ve also tested using granular keys (restricted to suspension actions) and a read-only key, but the issue persists.
- Interestingly, the endpoint works perfectly when accessed via a browser, but fails when using API requests with the key.
- The API key being used has full admin access, yet the requests continue to return a
Example Requests
curl
Example
curl -X PUT "https://your-discourse-domain.com/admin/users/15/suspend.json" \
-H "Api-Key: [REDACTED_API_KEY]" \
-H "Api-Username: system" \
-H "Content-Type: application/json" \
-d '{"suspend_until": "2024-12-31", "reason": "Violation of community guidelines"}'
PowerShell Example
# PowerShell Script to Suspend a User on Discourse
$baseUrl = "https://your-discourse-domain.com"
$userId = 15
$apiKey = "[REDACTED_API_KEY]"
$apiUsername = "system"
$suspendUntil = "2024-12-31"
$reason = "Violation of community guidelines"
$headers = @{
"Api-Key" = $apiKey
"Api-Username" = $apiUsername
"Content-Type" = "application/json"
}
$body = @{
suspend_until = $suspendUntil
reason = $reason
} | ConvertTo-Json
$endpoint = "$baseUrl/admin/users/$userId/suspend.json"
try {
$response = Invoke-RestMethod -Uri $endpoint -Method Put -Headers $headers -Body $body -ErrorAction Stop
Write-Host "User suspended successfully!" -ForegroundColor Green
} catch {
Write-Host "Error suspending user:" -ForegroundColor Red
Write-Host $_.Exception.Message
}
Additional Details
- Discourse Version: 3.4.0.beta3
- Troubleshooting Steps Taken:
I’ve tried adjusting request headers, includingUser-Agent
andReferer
, but to no avail.
Any insights or suggestions to help resolve these issues would be greatly appreciated. Thank you in advance for your time and support!
Best regards,
Ross