Skip to main content

Export API

Fetch a URL and stream the result in its native content type (HTML, PDF, image, etc.). While its capabilities may overlap with the /download API, the /export API is best suited for downloading files from a URL when you don't know the content type ahead of time — it automatically detects the file type and returns the appropriate response. It can also bundle all resources from a page (HTML, CSS, JavaScript, images, etc.) into a single ZIP file for convenient offline use.

Endpoint

  • Method: POST
  • Path: /export
  • Auth: token query parameter (?token=)
  • Content-Type: application/json
  • Response: */* (based on upstream content)

See the OpenAPI reference for complete details.

Quickstart

curl -X POST "https://production-sfo.browserless.io/export?token=YOUR_API_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{"url":"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf","gotoOptions":{"waitUntil":["networkidle0"]}}' \
-o output.pdf

Response

HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="output.pdf"

<binary>

For PDFs, images, or other binary content, the API returns the appropriate content type (e.g., application/pdf, image/jpeg) with a Content-Disposition: attachment header. The API returns the content in its native format. For HTML pages, you'll receive the HTML content with Content-Type: text/html.

Handling Different Content Types

The /export API automatically detects and returns content in its native format. Here's how to handle different response types in your code:

HTML Content

const response = await fetch(url, options);
if (response.headers.get('content-type')?.includes('text/html')) {
const htmlContent = await response.text();
// Process HTML content
}

PDF Content

const response = await fetch(url, options);
if (response.headers.get('content-type')?.includes('application/pdf')) {
const arrayBuffer = await response.arrayBuffer();
const pdfBuffer = Buffer.from(arrayBuffer);
// Save or process PDF buffer
}

Binary Content (Images, etc.)

const response = await fetch(url, options);
const contentType = response.headers.get('content-type');
if (contentType?.includes('image/') || !contentType?.includes('text/')) {
const arrayBuffer = await response.arrayBuffer();
const binaryBuffer = Buffer.from(arrayBuffer);
// Save or process binary buffer
}

Export with All Resources (Zip File)

When includeResources is set to true, the API returns a zip file containing the HTML and all linked resources (images, CSS, JavaScript):

curl -s -X POST "https://production-sfo.browserless.io/export?token=YOUR_API_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{"url":"https://quotes.toscrape.com/","includeResources":true}' \
-o rest-api-export-quotes.zip

Response

The API returns a zip file with Content-Type: application/zip and Content-Disposition: attachment header:

HTTP/1.1 200 OK
Content-Type: application/zip
Content-Disposition: attachment; filename="rest-api-export-quotes.zip"

[Binary zip file content containing HTML and all resources]

Configuration options

The /export API supports shared request configuration options that apply across REST endpoints: