Allscreenshots Docs
API reference

Async jobs

Process screenshots asynchronously with webhooks

Async jobs

For long-running captures or when you don't want to wait for the response, use async jobs. The API immediately returns a job ID, and you can poll for status or receive a webhook when complete.

Create async job

POST /v1/screenshots/async

Request body

Same parameters as the screenshots endpoint, plus:

ParameterTypeDescription
webhookUrlstringURL to receive completion notification
webhookSecretstringSecret for webhook signature verification

Example request

curl -X POST 'https://api.allscreenshots.com/v1/screenshots/async' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "url": "https://example.com",
    "fullPage": true,
    "webhookUrl": "https://your-server.com/webhooks/screenshot"
  }'

Response

{
  "jobId": "job_abc123xyz",
  "status": "pending",
  "createdAt": "2025-01-15T10:30:00Z"
}

Get job status

GET /v1/screenshots/jobs/{jobId}

Example request

curl 'https://api.allscreenshots.com/v1/screenshots/jobs/job_abc123xyz' \
  -H 'Authorization: Bearer YOUR_API_KEY'

Response (pending)

{
  "jobId": "job_abc123xyz",
  "status": "pending",
  "createdAt": "2025-01-15T10:30:00Z"
}

Response (completed)

{
  "jobId": "job_abc123xyz",
  "status": "completed",
  "createdAt": "2025-01-15T10:30:00Z",
  "completedAt": "2025-01-15T10:30:05Z",
  "result": {
    "url": "https://storage.allscreenshots.com/screenshots/abc123.png",
    "expiresAt": "2025-01-30T10:30:05Z",
    "size": 245678,
    "width": 1920,
    "height": 4500,
    "format": "png",
    "renderTime": 4250
  }
}

Response (failed)

{
  "jobId": "job_abc123xyz",
  "status": "failed",
  "createdAt": "2025-01-15T10:30:00Z",
  "completedAt": "2025-01-15T10:31:00Z",
  "error": {
    "code": "timeout",
    "message": "Page load timed out after 60 seconds"
  }
}

Get job result

Download the screenshot once the job is complete:

GET /v1/screenshots/jobs/{jobId}/result

Returns the image binary with appropriate content type.

curl 'https://api.allscreenshots.com/v1/screenshots/jobs/job_abc123xyz/result' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  --output screenshot.png

Job results are available for 24 hours after completion. Download or store them before expiration.

Job statuses

StatusDescription
pendingJob is queued for processing
processingScreenshot capture in progress
completedCapture successful, result available
failedCapture failed, error details available

Polling vs webhooks

Polling

Simple to implement but less efficient:

async function waitForJob(jobId) {
  while (true) {
    const response = await fetch(
      `https://api.allscreenshots.com/v1/screenshots/jobs/${jobId}`,
      { headers: { 'Authorization': `Bearer ${API_KEY}` } }
    );
    const job = await response.json();

    if (job.status === 'completed') {
      return job.result;
    }
    if (job.status === 'failed') {
      throw new Error(job.error.message);
    }

    await new Promise(resolve => setTimeout(resolve, 1000));
  }
}

More efficient—no polling required:

// Create job with webhook
const response = await fetch('https://api.allscreenshots.com/v1/screenshots/async', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://example.com',
    webhookUrl: 'https://your-server.com/webhooks/screenshot',
    webhookSecret: 'your-webhook-secret',
  }),
});

// Handle webhook in your server
app.post('/webhooks/screenshot', (req, res) => {
  // Verify signature (see Webhooks docs)
  const job = req.body;

  if (job.status === 'completed') {
    console.log('Screenshot ready:', job.result.url);
  }

  res.sendStatus(200);
});

See Webhooks for complete webhook documentation.

Use cases

Async jobs are ideal for:

  • Full page captures: Pages that take longer to render
  • Batch processing: When combined with bulk jobs
  • Background tasks: When you don't need immediate results
  • Long timeouts: Pages with heavy JavaScript or slow loading assets

Example workflow

// 1. Create async job
const { jobId } = await createAsyncJob({
  url: 'https://example.com/report',
  fullPage: true,
  waitUntil: 'networkidle',
});

// 2. Store job ID in your database
await db.screenshots.create({
  jobId,
  url: 'https://example.com/report',
  status: 'processing',
});

// 3. Process webhook when complete
app.post('/webhooks/screenshot', async (req, res) => {
  const { jobId, status, result, error } = req.body;

  await db.screenshots.update(jobId, {
    status,
    screenshotUrl: result?.url,
    error: error?.message,
  });

  res.sendStatus(200);
});

On this page