# Test alert webhook

POST http://localhost:5173/api/v1/private/alerts/webhooks/tests
Content-Type: application/json

Test alert webhook

Reference: https://www.comet.com/docs/opik/reference/rest-api/alerts/test-webhook

## OpenAPI Specification

```yaml
openapi: 3.1.1
info:
  title: Test alert webhook
  version: endpoint_alerts.testWebhook
paths:
  /v1/private/alerts/webhooks/tests:
    post:
      operationId: test-webhook
      summary: Test alert webhook
      description: Test alert webhook
      tags:
        - - subpackage_alerts
      parameters: []
      responses:
        '200':
          description: Webhook test
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebhookTestResult'
        '422':
          description: Unprocessable Content
          content: {}
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Alert_Write'
components:
  schemas:
    AlertWriteAlertType:
      type: string
      enum:
        - value: general
        - value: slack
        - value: pagerduty
    Webhook_Write:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        url:
          type: string
        secret_token:
          type: string
        headers:
          type: object
          additionalProperties:
            type: string
      required:
        - url
    AlertTriggerWriteEventType:
      type: string
      enum:
        - value: trace:errors
        - value: trace:feedback_score
        - value: trace_thread:feedback_score
        - value: prompt:created
        - value: prompt:committed
        - value: trace:guardrails_triggered
        - value: prompt:deleted
        - value: experiment:finished
        - value: trace:cost
        - value: trace:latency
    AlertTriggerConfigWriteType:
      type: string
      enum:
        - value: scope:project
        - value: threshold:feedback_score
        - value: threshold:cost
        - value: threshold:latency
        - value: threshold:errors
    AlertTriggerConfig_Write:
      type: object
      properties:
        id:
          type: string
          format: uuid
        type:
          $ref: '#/components/schemas/AlertTriggerConfigWriteType'
        config_value:
          type: object
          additionalProperties:
            type: string
      required:
        - type
    AlertTrigger_Write:
      type: object
      properties:
        id:
          type: string
          format: uuid
        event_type:
          $ref: '#/components/schemas/AlertTriggerWriteEventType'
        trigger_configs:
          type: array
          items:
            $ref: '#/components/schemas/AlertTriggerConfig_Write'
      required:
        - event_type
    Alert_Write:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        enabled:
          type: boolean
        alert_type:
          $ref: '#/components/schemas/AlertWriteAlertType'
        metadata:
          type: object
          additionalProperties:
            type: string
        webhook:
          $ref: '#/components/schemas/Webhook_Write'
        triggers:
          type: array
          items:
            $ref: '#/components/schemas/AlertTrigger_Write'
      required:
        - webhook
    WebhookTestResultStatus:
      type: string
      enum:
        - value: success
        - value: failure
    WebhookTestResult:
      type: object
      properties:
        status:
          $ref: '#/components/schemas/WebhookTestResultStatus'
        status_code:
          type: integer
        request_body:
          type: string
        error_message:
          type: string

```

## SDK Code Examples

```python
import requests

url = "http://localhost:5173/api/v1/private/alerts/webhooks/tests"

payload = { "webhook": { "url": "string" } }
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'http://localhost:5173/api/v1/private/alerts/webhooks/tests';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"webhook":{"url":"string"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "http://localhost:5173/api/v1/private/alerts/webhooks/tests"

	payload := strings.NewReader("{\n  \"webhook\": {\n    \"url\": \"string\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("http://localhost:5173/api/v1/private/alerts/webhooks/tests")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"webhook\": {\n    \"url\": \"string\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java
HttpResponse<String> response = Unirest.post("http://localhost:5173/api/v1/private/alerts/webhooks/tests")
  .header("Content-Type", "application/json")
  .body("{\n  \"webhook\": {\n    \"url\": \"string\"\n  }\n}")
  .asString();
```

```php
<?php

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:5173/api/v1/private/alerts/webhooks/tests', [
  'body' => '{
  "webhook": {
    "url": "string"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
var client = new RestClient("http://localhost:5173/api/v1/private/alerts/webhooks/tests");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"webhook\": {\n    \"url\": \"string\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = ["webhook": ["url": "string"]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:5173/api/v1/private/alerts/webhooks/tests")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```