> ## 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.

# Reset Circuit Breaker

Resets the circuit breaker for a webhook that was automatically disabled due to consecutive failures.

## Overview

When a webhook experiences too many consecutive delivery failures, the circuit breaker automatically opens to prevent further attempts. This endpoint allows you to reset the circuit breaker and re-enable the webhook after you've fixed the underlying issue.

## 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

Returns the updated webhook configuration with reset circuit breaker state.

<ResponseField name="consecutiveFailures" type="number">
  Reset to 0
</ResponseField>

<ResponseField name="circuitOpenedAt" type="string">
  Reset to null
</ResponseField>

<ResponseField name="isActive" type="boolean">
  Re-enabled (true)
</ResponseField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.instaview.sk/webhooks/550e8400-e29b-41d4-a716-446655440000/reset-circuit \
    -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}/reset-circuit`,
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.INSTAVIEW_API_KEY}`
      }
    }
  );

  const { data } = await response.json();
  console.log(`Circuit reset. Active: ${data.isActive}`);
  console.log(`Consecutive failures: ${data.consecutiveFailures}`);
  ```

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

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

  data = response.json()['data']
  print(f'Circuit reset. Active: {data["isActive"]}')
  print(f'Consecutive failures: {data["consecutiveFailures"]}')
  ```
</CodeGroup>

## Example Response

```json theme={null}
{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "apiKeyId": "api-key-uuid",
    "url": "https://api.example.com/webhooks/instaview",
    "name": "Production Webhook",
    "description": "Receives interview completion notifications",
    "headers": [
      { "name": "Authorization", "isMasked": true }
    ],
    "events": ["interview.completed", "analysis.completed"],
    "isActive": true,
    "maxRetries": 3,
    "timeoutMs": 30000,
    "consecutiveFailures": 0,
    "circuitOpenedAt": null,
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-16T09:00:00Z"
  }
}
```

## Circuit Breaker Workflow

<Steps>
  <Step title="Identify Problem">
    Check `consecutiveFailures` and `circuitOpenedAt` to confirm circuit is open
  </Step>

  <Step title="Fix Issue">
    Resolve the underlying problem (endpoint availability, authentication, etc.)
  </Step>

  <Step title="Test Endpoint">
    Use the [test endpoint](/api-reference/webhooks/test-webhook) to verify connectivity
  </Step>

  <Step title="Reset Circuit">
    Call this endpoint to re-enable the webhook
  </Step>

  <Step title="Monitor">
    Watch for new failures after reset
  </Step>
</Steps>

## Recommended Reset Procedure

```javascript theme={null}
async function safeResetCircuit(webhookId) {
  // 1. Check current state
  const { data: webhook } = await getWebhook(webhookId);
  
  if (!webhook.circuitOpenedAt) {
    console.log('Circuit is not open, no reset needed');
    return webhook;
  }
  
  console.log(`Circuit has been open since: ${webhook.circuitOpenedAt}`);
  console.log(`Consecutive failures: ${webhook.consecutiveFailures}`);
  
  // 2. Ensure webhook has ping event for testing
  if (!webhook.events.includes('ping')) {
    console.log('Adding ping event for testing...');
    await updateWebhook(webhookId, {
      events: [...webhook.events, 'ping']
    });
  }
  
  // 3. Test connectivity first
  console.log('Testing webhook connectivity...');
  const testResult = await testWebhook(webhookId);
  
  if (!testResult.success) {
    console.error('Webhook test failed:', testResult.message);
    console.error('Fix the issue before resetting circuit');
    return null;
  }
  
  console.log('Webhook test successful');
  
  // 4. Reset circuit
  console.log('Resetting circuit breaker...');
  const { data: resetWebhook } = await resetCircuit(webhookId);
  
  console.log(`Circuit reset. Webhook is now active: ${resetWebhook.isActive}`);
  
  return resetWebhook;
}
```

## Common Causes of Circuit Breaker Trips

<AccordionGroup>
  <Accordion title="Endpoint unavailable" icon="server">
    * Server crashed or was redeployed
    * DNS resolution failed
    * Network connectivity issues

    **Fix**: Ensure your endpoint is up and accessible
  </Accordion>

  <Accordion title="Authentication failures" icon="key">
    * API token expired
    * Custom header value changed
    * Authentication endpoint down

    **Fix**: Update the webhook's custom headers with valid credentials
  </Accordion>

  <Accordion title="Timeout issues" icon="clock">
    * Endpoint taking too long to respond
    * Long-running synchronous processing
    * Network latency

    **Fix**: Acknowledge webhooks immediately and process asynchronously
  </Accordion>

  <Accordion title="Response errors" icon="circle-xmark">
    * Application errors (5xx)
    * Validation failures (4xx)
    * Incorrect response format

    **Fix**: Check your application logs and fix the errors
  </Accordion>
</AccordionGroup>

## Error Responses

<AccordionGroup>
  <Accordion title="404 - Webhook Not Found">
    ```json theme={null}
    {
      "success": false,
      "error": {
        "code": "RESOURCE_NOT_FOUND",
        "message": "Webhook configuration not found"
      }
    }
    ```
  </Accordion>

  <Accordion title="403 - Access Denied">
    ```json theme={null}
    {
      "success": false,
      "error": {
        "code": "RESOURCE_ACCESS_DENIED",
        "message": "Access denied to this webhook configuration"
      }
    }
    ```
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card title="Test Webhook" icon="flask" href="/api-reference/webhooks/test-webhook">
    Test connectivity before resetting
  </Card>

  <Card title="Get Webhook" icon="eye" href="/api-reference/webhooks/get-webhook">
    Check circuit breaker status
  </Card>
</CardGroup>
