# Test an alert channel — API reference

> Sends a test notification through the selected alert channel.

Source: https://upfour.io/docs/api/notification-channels/test-an-alert-channel

[Developers](https://upfour.io/docs/api.md)/[Alert channels](https://upfour.io/docs/api/notification-channels.md)

Sends a test notification through the selected alert channel.

POST https://app.upfour.io/v1/notification_channels/{channelID}/test

scope notification_channel.write stable [Idempotency-Key supported](https://upfour.io/docs/api/idempotency.md) returns 200

## Parameters

| Field | Type | Description |
| --- | --- | --- |
| `channelID` required | uuid | path parameter |

## Returns

A successful request returns `200` with application/json.

Response fields 1 top-level fields

| Field | Type | Description |
| --- | --- | --- |
| `data` | NotificationChannelTestResponse | |
| NotificationChannelTestResponse · 1 fields FieldTypeDescription `message` string | | |

## Errors

Only the errors this operation can return. Every error uses the [same envelope](https://upfour.io/docs/api/responses.md).

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | [bad_request](https://upfour.io/docs/api/errors#code-bad_request) | The request is malformed or fails validation. |
| 402 | [billing_action_unavailable](https://upfour.io/docs/api/errors#code-billing_action_unavailable) | The Company's billing state does not allow this action. **When:** A metered or limited action while the billing state, such as paused or without credit, blocks it; details holds the action and billing_state. **Fix:** Top up the credit or change the plan, then retry. |
| 502 | [channel_test_failed](https://upfour.io/docs/api/errors#code-channel_test_failed) | The alert channel's provider could not deliver the test. **When:** Sending a test alert to a channel when the provider fails in a way that fits none of the other provider codes. **Fix:** Check the channel's address and settings, then test again. |
| 404 | [not_found](https://upfour.io/docs/api/errors#code-not_found) | The requested resource does not exist or is outside the caller's scope. |
| 403 | [permission_denied](https://upfour.io/docs/api/errors#code-permission_denied) | The credentials do not permit this action. |
| 422 | [provider_auth_rejected](https://upfour.io/docs/api/errors#code-provider_auth_rejected) | The alert channel's provider rejected the credentials. **When:** A test alert whose provider answered 401 or 403. **Fix:** Check the token, secret or account details of the channel. |
| 422 | [provider_rejected](https://upfour.io/docs/api/errors#code-provider_rejected) | The alert channel's provider rejected the test. **When:** A test alert whose provider answered 400, 404, 405, 410 or 422. **Fix:** Check the channel's address and settings. |
| 504 | [provider_timeout](https://upfour.io/docs/api/errors#code-provider_timeout) | The alert channel's provider did not answer in time. **When:** A test alert whose provider took too long to respond. **Fix:** Check the address and try again later. |
| 422 | [provider_unreachable](https://upfour.io/docs/api/errors#code-provider_unreachable) | The alert channel's address cannot be reached. **When:** A test alert to a host that does not resolve, refuses the connection, has an invalid URL or an invalid HTTPS certificate. **Fix:** Check the URL and its HTTPS certificate. |
| 503 | [quota_gate_unavailable](https://upfour.io/docs/api/errors#code-quota_gate_unavailable) | The limit check itself failed, so the action was not carried out. **When:** The quota service could not decide while the request ran. **Fix:** Retry in a moment; nothing was changed. |
| 403 / 429 | [quota_limit_reached](https://upfour.io/docs/api/errors#code-quota_limit_reached) | A usage or inventory limit of the Company was reached. **When:** Counters and concurrency limits answer 429 with Retry-After, inventory and capacity limits answer 403; details holds purpose, limit and window. **Fix:** On 429 wait Retry-After seconds; on 403 free something up, request a higher limit where details.raise_request is true, or buy an extension. |
| 503 | [test_unavailable](https://upfour.io/docs/api/errors#code-test_unavailable) | Sending a test is not possible right now. **When:** A test alert request while the test sender cannot take it. **Fix:** Try again in a moment. |

Every call can also return `unauthorized` (401), `rate_limit_exceeded` (429) or `internal_error` (500 / 502). See [Responses and errors](https://upfour.io/docs/api/responses.md).

[PreviousDelete an alert channel](https://upfour.io/docs/api/notification-channels/delete-an-alert-channel.md)

## Request

### cURL

```bash
curl -s -X POST "https://app.upfour.io/v1/notification_channels/00000000-0000-4000-8000-000000000001/test" \
  -H "Authorization: Bearer $UP4_API_KEY"
```

### JavaScript

```javascript
const res = await fetch("https://app.upfour.io/v1/notification_channels/00000000-0000-4000-8000-000000000001/test", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.UP4_API_KEY}`,
  },
});
console.log(res.status, await res.json());
```

### Python

```python
import os
import requests

res = requests.post(
    "https://app.upfour.io/v1/notification_channels/00000000-0000-4000-8000-000000000001/test",
    headers={"Authorization": f"Bearer {os.environ['UP4_API_KEY']}"},
)
print(res.status_code, res.json())
```

### Go

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	req, _ := http.NewRequest("POST", "https://app.upfour.io/v1/notification_channels/00000000-0000-4000-8000-000000000001/test", nil)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("UP4_API_KEY"))
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	out, _ := io.ReadAll(res.Body)
	fmt.Println(res.StatusCode, string(out))
}
```

### PHP

```php
<?php
$ch = curl_init("https://app.upfour.io/v1/notification_channels/00000000-0000-4000-8000-000000000001/test");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("UP4_API_KEY"),
    ],
]);
$response = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), " ", $response, "\n";
curl_close($ch);
```

## Response

### 200

```json
{
  "data": {
    "message": "Test notification sent successfully"
  }
}
```

### 400

```json
{
  "error": {
    "code": "bad_request",
    "message": "The request is malformed or fails validation.",
    "request_id": "req_…"
  }
}
```

### 402

```json
{
  "error": {
    "code": "billing_action_unavailable",
    "message": "The Company's billing state does not allow this action.",
    "request_id": "req_…"
  }
}
```

### 403

```json
{
  "error": {
    "code": "permission_denied",
    "message": "The credentials do not permit this action.",
    "request_id": "req_…"
  }
}
```

### 404

```json
{
  "error": {
    "code": "not_found",
    "message": "The requested resource does not exist or is outside the caller's scope.",
    "request_id": "req_…"
  }
}
```

### 422

```json
{
  "error": {
    "code": "provider_auth_rejected",
    "message": "The alert channel's provider rejected the credentials.",
    "request_id": "req_…"
  }
}
```

### 429

```json
{
  "error": {
    "code": "quota_limit_reached",
    "message": "A usage or inventory limit of the Company was reached.",
    "request_id": "req_…"
  }
}
```

### 502

```json
{
  "error": {
    "code": "channel_test_failed",
    "message": "The alert channel's provider could not deliver the test.",
    "request_id": "req_…"
  }
}
```

### 503

```json
{
  "error": {
    "code": "quota_gate_unavailable",
    "message": "The limit check itself failed, so the action was not carried out.",
    "request_id": "req_…"
  }
}
```

### 504

```json
{
  "error": {
    "code": "provider_timeout",
    "message": "The alert channel's provider did not answer in time.",
    "request_id": "req_…"
  }
}
```
