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

# Unubscribe to Webhooks

> Remove webhook subscriptions to stop receiving real-time notifications for specific events.

## Overview

Delete an existing webhook subscription to stop receiving notifications for subscribed events. This endpoint is used by Zapier when users remove or disable trigger integrations, ensuring clean webhook management and preventing unnecessary API calls.

<Note>
  This endpoint is primarily used by Zapier integrations but can be used with any webhook service that follows the same pattern.
</Note>

## Authentication

All requests require a valid API key in the Authorization header:

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

## Delete Webhook

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE 'https://app.timetracker.in/api/integrations/zapier/webhooks/wh_1234567890abcdef' \
    -H 'Authorization: Bearer YOUR_API_KEY'
  ```

  ```javascript JavaScript theme={null}
  const webhookId = 'wh_1234567890abcdef';

  const response = await fetch(`https://app.timetracker.in/api/integrations/zapier/webhooks/${webhookId}`, {
    method: 'DELETE',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });

  const result = await response.json();
  ```

  ```python Python theme={null}
  import requests

  webhook_id = 'wh_1234567890abcdef'
  url = f"https://app.timetracker.in/api/integrations/zapier/webhooks/{webhook_id}"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY"
  }

  response = requests.delete(url, headers=headers)
  result = response.json()
  ```
</CodeGroup>

### Path Parameters

<ParamField path="id" type="string" required>
  The unique identifier of the webhook subscription to delete.

  **Format**: Webhook ID (e.g., `wh_1234567890abcdef`)

  **Example**: `wh_1234567890abcdef`
</ParamField>

## Response

### Success Response

```json theme={null}
{
  "success": true
}
```

<ResponseField name="success" type="boolean">
  Confirms successful webhook deletion.
</ResponseField>

### Error Responses

<AccordionGroup>
  <Accordion title="400 Bad Request - Webhook Not Found">
    ```json theme={null}
    {
      "error": "Webhook not found"
    }
    ```

    The specified webhook ID doesn't exist or has already been deleted.
  </Accordion>

  <Accordion title="400 Bad Request - Deletion Failed">
    ```json theme={null}
    {
      "error": "Failed to delete webhook"
    }
    ```

    The webhook exists but couldn't be deleted due to system constraints.
  </Accordion>

  <Accordion title="401 Unauthorized">
    ```json theme={null}
    {
      "error": "Unauthorized"
    }
    ```

    Invalid or missing API key in the Authorization header.
  </Accordion>

  <Accordion title="401 Unauthorized - User ID Not Found">
    ```json theme={null}
    {
      "error": "User ID not found in authentication result"
    }
    ```

    The API key is valid but doesn't contain the required user identification.
  </Accordion>

  <Accordion title="500 Internal Server Error">
    ```json theme={null}
    {
      "error": "Internal server error"
    }
    ```

    An unexpected server error occurred. Try again or contact support.
  </Accordion>
</AccordionGroup>

## Zapier Integration Usage

### Automatic Cleanup

Zapier automatically calls this endpoint when:

<Steps>
  <Step title="Trigger Removal">
    When users delete a Zap that contains webhook triggers, Zapier calls this endpoint to clean up the subscription.
  </Step>

  <Step title="Integration Disconnection">
    When users disconnect the Timetracker integration from their Zapier account, all associated webhooks are automatically removed.
  </Step>

  <Step title="Error Recovery">
    If a webhook subscription fails or becomes invalid, Zapier may attempt to clean it up to prevent future issues.
  </Step>
</Steps>

### Webhook Lifecycle

<AccordionGroup>
  <Accordion title="Creation">
    **Subscribe**: When setting up a trigger, Zapier calls the subscribe endpoint to create a webhook subscription.
  </Accordion>

  <Accordion title="Active State">
    **Monitoring**: The webhook remains active and receives event notifications until deleted.
  </Accordion>

  <Accordion title="Deletion">
    **Cleanup**: When no longer needed, Zapier calls this delete endpoint to remove the subscription.
  </Accordion>
</AccordionGroup>

## Important Notes

<Warning>
  **Immediate Effect**: Webhook deletion takes effect immediately. No further notifications will be sent to the registered URL after successful deletion.
</Warning>

<Info>
  **Idempotent Operation**: Deleting a non-existent webhook returns a success response, making this operation safe to retry.
</Info>

<Check>
  **Best Practices**:

  * Always store webhook IDs when creating subscriptions for later cleanup
  * Implement proper error handling for deletion failures
  * Consider implementing webhook health checks to detect stale subscriptions
  * Use HTTPS endpoints only for security
  * Monitor webhook deletion logs for integration health
</Check>

## Webhook Management

### Finding Webhook IDs

To find webhook IDs for deletion, you can:

1. **Store during creation**: Save the webhook ID returned from the subscribe endpoint
2. **List webhooks**: Use the webhook listing endpoint (if available) to find active subscriptions
3. **Zapier management**: Check your Zapier account's webhook management interface

### Bulk Cleanup

For managing multiple webhooks:

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Example: Delete multiple webhooks
  const webhookIds = ['wh_123', 'wh_456', 'wh_789'];

  for (const webhookId of webhookIds) {
    try {
      const response = await fetch(`https://app.timetracker.in/api/integrations/zapier/webhooks/${webhookId}`, {
        method: 'DELETE',
        headers: {
          'Authorization': 'Bearer YOUR_API_KEY'
        }
      });
      
      if (response.ok) {
        console.log(`Deleted webhook: ${webhookId}`);
      }
    } catch (error) {
      console.error(`Failed to delete webhook ${webhookId}:`, error);
    }
  }
  ```

  ```python Python theme={null}
  # Example: Delete multiple webhooks
  import requests

  webhook_ids = ['wh_123', 'wh_456', 'wh_789']
  headers = {"Authorization": "Bearer YOUR_API_KEY"}

  for webhook_id in webhook_ids:
      try:
          url = f"https://app.timetracker.in/api/integrations/zapier/webhooks/{webhook_id}"
          response = requests.delete(url, headers=headers)
          
          if response.status_code == 200:
              print(f"Deleted webhook: {webhook_id}")
      except Exception as e:
          print(f"Failed to delete webhook {webhook_id}: {e}")
  ```
</CodeGroup>

## Security Considerations

<Warning>
  **Access Control**: Only the user who created a webhook can delete it. Webhook IDs are workspace-specific and cannot be accessed across different user accounts.
</Warning>

<Info>
  **Audit Trail**: Webhook deletions are logged for security and compliance purposes. Consider implementing audit logging in your applications.
</Info>

## Troubleshooting

### Common Issues

<AccordionGroup>
  <Accordion title="Webhook Not Found Error">
    **Cause**: The webhook ID is incorrect or the webhook was already deleted.

    **Solution**:

    * Verify the webhook ID is correct
    * Check if the webhook was already deleted
    * Ensure you're using the correct API key for the workspace
  </Accordion>

  <Accordion title="Authentication Failures">
    **Cause**: Invalid API key or missing authorization header.

    **Solution**:

    * Verify your API key is correct and active
    * Ensure the Authorization header is properly formatted
    * Check that your API key has the necessary permissions
  </Accordion>

  <Accordion title="Persistent Webhooks">
    **Cause**: Webhook appears to still be active after deletion.

    **Solution**:

    * Wait a few minutes for the deletion to propagate
    * Check if multiple webhooks exist for the same URL
    * Verify the webhook ID was correct
  </Accordion>
</AccordionGroup>

## Integration Testing

To test webhook deletion in your integration:

1. **Create a test webhook** using the subscribe endpoint
2. **Store the webhook ID** returned in the response
3. **Delete the webhook** using this endpoint
4. **Verify deletion** by attempting to trigger the webhook (should fail)
5. **Clean up any test data** created during testing

This ensures your integration properly handles the complete webhook lifecycle.
