Webhook URL Parameter

The webhook_url parameter enables asynchronous image generation, which is essential for the Screenshot API or larger images.

Specifications

PropertyValue
Typestring
RequiredNo
Defaultnull
APIBoth HTML/CSS and Screenshot APIs

Description

When provided, the API will:

  1. Immediately return a success response with a processing status and filename
  2. Continue processing the image in the background
  3. Send a POST request to your webhook URL when the image is ready or if an error occurs

We strongly recommend using webhooks for:

  • Screenshot API requests
  • Images with high DPI values (2-4)
  • Full page captures
  • Large viewport dimensions

Examples

Screenshot API Example (https://app.html2img.com/api/screenshot)

{
    "url": "https://example.com",
    "webhook_url": "https://your-domain.com/webhook"
}

Initial Response:

{
    "message": "Screenshot generation started",
    "filename": "image-1641234567890-123456.png",
    "status": "processing",
    "log_id": "ab12345cd-6aa2-4927-9afe-012345abc123"
}

HTML API Example (https://app.html2img.com/api/html)

{
    "html": "<h1>Large Content</h1>",
    "dpi": 3,
    "webhook_url": "https://your-domain.com/webhook"
}

Webhook Responses

Webhook Success Response:

{
    "status": "success",
    "message": "Screenshot generated successfully",
    "url": "https://i.html2img.com/image-1641234567890-123456.png",
    "filename": "image-1641234567890-123456.png",
    "log_id": "ab12345cd-6aa2-4927-9afe-012345abc123",
    "dpi": 1
}

Webhook Error Response:

{
    "status": "error",
    "error": "The request timed out. Please try again.",
    "filename": "image-1641234567890-123456.png",
    "log_id": "ab12345cd-6aa2-4927-9afe-012345abc123"
}

Your webhook endpoint should:

  • Be publicly accessible
  • Accept POST requests with JSON content
  • Handle both success and error responses
  • Process the response asynchronously (don’t block)