# API is throwing 404 errors

**URL:** https://meta.discourse.org/t/api-is-throwing-404-errors/335647
**Category:** Support
**Created:** [November 11, 2024, 7:17pm UTC](https://meta.discourse.org/t/api-is-throwing-404-errors/335647 "2024-11-11T19:17:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lmno](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lmno/32/463544_2.png) [@lmno](https://meta.discourse.org/u/lmno)
#### Post date: [November 11, 2024, 7:17pm UTC](https://meta.discourse.org/t/api-is-throwing-404-errors/335647/1 "2024-11-11T19:17:33Z")

</div>

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

1. **404 Not Found** :

2. **Unexpected HTML Response** :

3. **API Key and Permissions** :

### Example Requests

#### `curl` Example

```bash
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
# 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, including `User-Agent` and `Referer`, 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

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 11, 2024, 7:33pm UTC](https://meta.discourse.org/t/api-is-throwing-404-errors/335647/2 "2024-11-11T19:33:42Z")

</div>

Your example works as-is modulo the expected parameters against our test site:

```plaintext
○ → curl -i -X PUT "https://try.discourse.org/admin/users/41/suspend.json" \
  -H "Api-Key: swordfish" \
  -H "Api-Username: michael" \
  -H "Content-Type: application/json" \
  -d '{"suspend_until": "2024-12-31", "reason": "Violation of community guidelines"}'

HTTP/2 200 
server: nginx
date: Mon, 11 Nov 2024 19:27:44 GMT
content-type: application/json; charset=utf-8
vary: Accept-Encoding
x-frame-options: SAMEORIGIN
x-xss-protection: 0
x-content-type-options: nosniff
x-permitted-cross-domain-policies: none
referrer-policy: strict-origin-when-cross-origin
x-discourse-username: michael
x-discourse-route: users/suspend
cache-control: no-cache, no-store
x-request-id: fe9c5ddc-b11a-45ba-ab41-9403eb53f255
cdck-proxy-id: app-router-tiehunter03.sea1
strict-transport-security: max-age=31536000
cdck-proxy-id: app-balancer-tieinterceptor1b.sea1

{
  "suspension": {
    "suspend_reason": "Violation of community guidelines",
    "full_suspend_reason": "Violation of community guidelines",
    "suspended_till": "2024-12-31T00:00:00.000Z",
    "suspended_at": "2024-11-11T19:27:44.927Z",
    "suspended_by": {
      "id": 85,
      "username": "michael",
      "name": "Michael Brown",
      "avatar_template": "/user_avatar/try.discourse.org/michael/{size}/639_2.png"
    }
  }
}

```

- validate the API key  
does Discourse show a valid user authentication (`x-discourse-username`) when making a simple GET with that key?
- validate the user ID  
it _really_ exists, right? it’ll 404 if it doesn’t
- are you behind Cloudflare?  
it can mess with parameters

---

<div class="post-metadata">

### Author: ![lmno](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lmno/32/463544_2.png) [@lmno](https://meta.discourse.org/u/lmno)
#### Post date: [November 11, 2024, 8:06pm UTC](https://meta.discourse.org/t/api-is-throwing-404-errors/335647/3 "2024-11-11T20:06:59Z")

</div>

> [@supermathie](#):
>
> - validate the API key  
> does Discourse show a valid user authentication (`x-discourse-username`) when making a simple GET with that key?
> - validate the user ID  
> it _really_ exists, right? it’ll 404 if it doesn’t
> - are you behind Cloudflare?  
> it can mess with parameters

1. **API Key Validation**  
The API key was confirmed to be valid using the following command:

2. **User Existence Confirmation**  
The test user (ID: 15) was verified to exist, as demonstrated by querying the user’s data using `/admin/users/15/suspend.json`.:

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/8/c/a8c481fcd8b1e5986528266b1a5a35e25fde0054.png)

1. **Network Configuration**  
The site is not utilizing Cloudflare. Instead, it operates behind an NGINX reverse proxy. The application listens on port `8080` internally, with NGINX handling SSL termination on port `443` for external access. The `app.yml` configuration does not bind directly to port `443`, as SSL and certificate management are handled by NGINX to ensure secure connectivity and availability.

---

<div class="post-metadata">

### Author: ![Gabriel\_Underwood](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gabriel_underwood/32/462633_2.png) [@Gabriel\_Underwood](https://meta.discourse.org/u/Gabriel_Underwood)
#### Post date: [May 16, 2025, 4:05pm UTC](https://meta.discourse.org/t/api-is-throwing-404-errors/335647/4 "2025-05-16T16:05:17Z")

</div>

Hi,  
Just to follow up on this I believe the global scope on API keys is missing the suspend scope. I was running into the same error. I had to swap my key to a granular key with the suspend scope to get it to work. I was also hoping to have the unsuspend working but it does not seem available through the API yet
