Home / HTML snapshots and screenshots: workflow

HTML snapshots and screenshots: workflow

Retrieve saved HTML and a page screenshot from a selected Diff check. Account for file retention and the reason a stored file is unavailable.

On this page

These methods belong to Change monitoring. Download the saved HTML or PNG screenshot of a page as captured during a selected check. These are report snapshots, not downloads of the current live page.

First retrieve report rows with include_state=true. Copy the required page’s url_md5 and check the state.files fields below. Use the same project, report, and page in the download request. For screenshots, set device=desktop or device=mobile; the default is desktop.

Parameter Description
state.files.html_available HTML snapshot availability
state.files.screenshot_desktop_available Desktop screenshot availability
state.files.screenshot_mobile_available Mobile screenshot availability
state.files.*_expires_at / state.files.*_expires_in_days Expiry date and remaining days for the corresponding file. Values may be absent when the retention period is unknown.

Retention belongs to the selected check. Changing project settings does not change the retention of files already paid for. 404 file_not_available means the file is missing, expired, or exceeds 10 MB. HTML is returned as text/html; screenshots as image/png.

  • Scope for HTML: diff-htmlfiles:read.
  • Scope for screenshots: diff-screenshot:read.

GET /public-api/v1/diff-projects/{diff_project_id}/reports/{report_id}/pages/{url_md5}/html

Download the page HTML captured for the selected report.

GET /public-api/v1/diff-projects/{diff_project_id}/reports/{report_id}/pages/{url_md5}/screenshot

Download a screenshot. Query: device=desktop or device=mobile.

Download HTML

curl

curl --fail-with-body --silent --show-error --location \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Accept: text/html' \
  --output 'page.html' \
  'https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html'

JavaScript

const { writeFile } = require("node:fs/promises")

async function main () {
  const response = await fetch("https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html", {
    method: "GET",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Accept": "text/html",
    },
    signal: AbortSignal.timeout(30_000),
  })

  if (!response.ok) {
    const responseText = await response.text()
    throw new Error(`HTTP ${response.status}: ${responseText}`)
  }

  await writeFile("page.html", Buffer.from(await response.arrayBuffer()))
}

main().catch(error => {
  console.error(error)
  process.exitCode = 1
})

Python

import json
from pathlib import Path
import requests

url = "https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Accept": "text/html",
}

response = requests.request(
    "GET",
    url,
    headers=headers,
    timeout=30,
)
response.raise_for_status()
Path("page.html").write_bytes(response.content)

PHP

<?php

$curl = curl_init('https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html');

if ($curl === false) {
    throw new RuntimeException('Unable to initialize cURL');
}

curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer YOUR_API_KEY',
        'Accept: text/html',
    ],
]);

$response = curl_exec($curl);

if ($response === false) {
    $message = curl_error($curl);
    curl_close($curl);
    throw new RuntimeException('Network error: ' . $message);
}

$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE) ?: '';
curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException("HTTP $status: $response");
}

if (file_put_contents('page.html', $response) === false) {
    throw new RuntimeException('Unable to save response file');
}

Go

package main

import (
	"context"
	"fmt"
	"io"
	"net/http"
	"os"
	"time"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 30 * time.Second)
	defer cancel()

	request, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html", nil)
	if err != nil {
		panic(err)
	}

	request.Header.Set("Authorization", "Bearer YOUR_API_KEY")
	request.Header.Set("Accept", "text/html")

	client := &http.Client{Timeout: 30 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusMultipleChoices {
		errorBody, readErr := io.ReadAll(response.Body)
		if readErr != nil {
			panic(readErr)
		}
		panic(fmt.Sprintf("HTTP %d: %s", response.StatusCode, errorBody))
	}

	output, err := os.Create("page.html")
	if err != nil {
		panic(err)
	}

	if _, err := io.Copy(output, response.Body); err != nil {
		output.Close()
		panic(err)
	}
	if err := output.Close(); err != nil {
		panic(err)
	}
}

Google Apps Script

function callLabrikaPublicAPI() {
  const response = UrlFetchApp.fetch("https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/html", {
    method: "get",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Accept": "text/html",
    },
    followRedirects: false,
    muteHttpExceptions: true,
  });
  const status = response.getResponseCode();
  if (status < 200 || status >= 300) {
    throw new Error('HTTP ' + status + ': ' + response.getContentText());
  }
  DriveApp.createFile(response.getBlob().setName("page.html"));
}

Download PNG

curl

curl --fail-with-body --silent --show-error --location \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Accept: image/png' \
  --output 'screenshot.png' \
  'https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop'

JavaScript

const { writeFile } = require("node:fs/promises")

async function main () {
  const response = await fetch("https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop", {
    method: "GET",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Accept": "image/png",
    },
    signal: AbortSignal.timeout(30_000),
  })

  if (!response.ok) {
    const responseText = await response.text()
    throw new Error(`HTTP ${response.status}: ${responseText}`)
  }

  await writeFile("screenshot.png", Buffer.from(await response.arrayBuffer()))
}

main().catch(error => {
  console.error(error)
  process.exitCode = 1
})

Python

import json
from pathlib import Path
import requests

url = "https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Accept": "image/png",
}

response = requests.request(
    "GET",
    url,
    headers=headers,
    timeout=30,
)
response.raise_for_status()
Path("screenshot.png").write_bytes(response.content)

PHP

<?php

$curl = curl_init('https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop');

if ($curl === false) {
    throw new RuntimeException('Unable to initialize cURL');
}

curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer YOUR_API_KEY',
        'Accept: image/png',
    ],
]);

$response = curl_exec($curl);

if ($response === false) {
    $message = curl_error($curl);
    curl_close($curl);
    throw new RuntimeException('Network error: ' . $message);
}

$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE) ?: '';
curl_close($curl);

if ($status < 200 || $status >= 300) {
    throw new RuntimeException("HTTP $status: $response");
}

if (file_put_contents('screenshot.png', $response) === false) {
    throw new RuntimeException('Unable to save response file');
}

Go

package main

import (
	"context"
	"fmt"
	"io"
	"net/http"
	"os"
	"time"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 30 * time.Second)
	defer cancel()

	request, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop", nil)
	if err != nil {
		panic(err)
	}

	request.Header.Set("Authorization", "Bearer YOUR_API_KEY")
	request.Header.Set("Accept", "image/png")

	client := &http.Client{Timeout: 30 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusMultipleChoices {
		errorBody, readErr := io.ReadAll(response.Body)
		if readErr != nil {
			panic(readErr)
		}
		panic(fmt.Sprintf("HTTP %d: %s", response.StatusCode, errorBody))
	}

	output, err := os.Create("screenshot.png")
	if err != nil {
		panic(err)
	}

	if _, err := io.Copy(output, response.Body); err != nil {
		output.Close()
		panic(err)
	}
	if err := output.Close(); err != nil {
		panic(err)
	}
}

Google Apps Script

function callLabrikaPublicAPI() {
  const response = UrlFetchApp.fetch("https://app.labrika.com/public-api/v1/diff-projects/PROJECT_ID/reports/last/pages/URL_MD5/screenshot?device=desktop", {
    method: "get",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Accept": "image/png",
    },
    followRedirects: false,
    muteHttpExceptions: true,
  });
  const status = response.getResponseCode();
  if (status < 200 || status >= 300) {
    throw new Error('HTTP ' + status + ': ' + response.getContentText());
  }
  DriveApp.createFile(response.getBlob().setName("screenshot.png"));
}