> ## Documentation Index
> Fetch the complete documentation index at: https://docs.instaview.sk/llms.txt
> Use this file to discover all available pages before exploring further.

# Test Webhook

Sends a test ping event to verify webhook connectivity and signature validation.

## Overview

Use this endpoint to verify that your webhook endpoint is correctly configured and can receive and validate webhook payloads. The test sends a `ping` event to your endpoint.

<Info>
  The webhook must be subscribed to the `ping` event for testing to work.
</Info>

## Authentication

<ParamField header="Authorization" type="string" required>
  Bearer token with `write:webhooks` scope
</ParamField>

## Path Parameters

<ParamField path="id" type="string" required>
  The webhook configuration ID (UUID v4)
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Whether the test was successful
</ResponseField>

<ResponseField name="deliveryId" type="string">
  Unique delivery ID for tracking (only on success)
</ResponseField>

<ResponseField name="httpStatus" type="number">
  HTTP status code returned by your endpoint (only on success)
</ResponseField>

<ResponseField name="durationMs" type="number">
  Request duration in milliseconds (only on success)
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable result message
</ResponseField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.instaview.sk/webhooks/550e8400-e29b-41d4-a716-446655440000/test \
    -H "Authorization: Bearer sk_your_key_here"
  ```

  ```javascript Node.js theme={null}
  const webhookId = '550e8400-e29b-41d4-a716-446655440000';

  const response = await fetch(
    `https://api.instaview.sk/webhooks/${webhookId}/test`,
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.INSTAVIEW_API_KEY}`
      }
    }
  );

  const { data } = await response.json();

  if (data.success) {
    console.log('✅ Webhook test successful');
    console.log(`   Response time: ${data.durationMs}ms`);
    console.log(`   HTTP status: ${data.httpStatus}`);
  } else {
    console.error('❌ Webhook test failed:', data.message);
  }
  ```

  ```python Python theme={null}
  webhook_id = '550e8400-e29b-41d4-a716-446655440000'

  response = requests.post(
      f'https://api.instaview.sk/webhooks/{webhook_id}/test',
      headers={
          'Authorization': f'Bearer {os.environ["INSTAVIEW_API_KEY"]}'
      }
  )

  data = response.json()['data']

  if data['success']:
      print('✅ Webhook test successful')
      print(f'   Response time: {data["durationMs"]}ms')
      print(f'   HTTP status: {data["httpStatus"]}')
  else:
      print(f'❌ Webhook test failed: {data["message"]}')
  ```
</CodeGroup>

## Example Responses

### Successful Test

```json theme={null}
{
  "success": true,
  "data": {
    "success": true,
    "deliveryId": "delivery-uuid",
    "httpStatus": 200,
    "durationMs": 156,
    "message": "Webhook test successful!"
  }
}
```

### Failed Test

```json theme={null}
{
  "success": true,
  "data": {
    "success": false,
    "message": "Webhook test failed: Connection timeout"
  }
}
```

### Missing Ping Event Subscription

```json theme={null}
{
  "success": true,
  "data": {
    "success": false,
    "message": "Webhook is not subscribed to ping events. Add the ping event to the webhook configuration."
  }
}
```

### Webhook Disabled

```json theme={null}
{
  "success": true,
  "data": {
    "success": false,
    "message": "No delivery was created. This may indicate the webhook is disabled or circuit breaker is open."
  }
}
```

## Test Payload

Your endpoint will receive this payload during testing:

```json theme={null}
{
  "event": "ping",
  "timestamp": "2024-01-20T14:30:00.000Z",
  "deliveryId": "delivery-uuid",
  "data": {
    "message": "Test ping from InstaView webhook system"
  }
}
```

## Verifying Signature in Test

Use the test to verify your signature validation is working correctly:

```javascript theme={null}
// Configure Express to preserve raw body for signature verification
app.post('/webhooks/instaview', 
  express.raw({ type: 'application/json' }),
  (req, res) => {
    const signature = req.headers['x-webhook-signature'];
    const payload = req.body.toString(); // Now this is the raw buffer
    
    if (!verifySignature(payload, signature, process.env.WEBHOOK_SECRET)) {
      console.error('Signature verification failed');
      return res.status(401).send('Invalid signature');
    }
    
    const event = JSON.parse(payload);
    
    if (event.event === 'ping') {
      console.log('Ping test received successfully');
      console.log('Message:', event.data.message);
    }
    
    res.status(200).send('OK');
  }
);
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Test fails with timeout">
    * Ensure your endpoint is publicly accessible
    * Check if your firewall allows incoming connections
    * Verify your endpoint responds within 30 seconds
  </Accordion>

  <Accordion title="Test fails with connection refused">
    * Verify the webhook URL is correct
    * Check if your server is running
    * Ensure the port is open and accessible
  </Accordion>

  <Accordion title="Test fails with 401/403">
    * Check your custom Authorization header value
    * Verify your endpoint's authentication logic
    * Ensure signature verification is working correctly
  </Accordion>

  <Accordion title="'Not subscribed to ping events'">
    Add the ping event to your webhook:

    ```javascript theme={null}
    await fetch(`/webhooks/${webhookId}`, {
      method: 'PATCH',
      headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
      body: JSON.stringify({
        events: ["ping", "interview.completed", "analysis.completed"]
      })
    });
    ```
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card title="Webhooks Guide" icon="webhook" href="/guides/webhooks">
    Learn about signature verification
  </Card>

  <Card title="Update Webhook" icon="pen" href="/api-reference/webhooks/update-webhook">
    Add ping event subscription
  </Card>
</CardGroup>
