Zyte API initial setup#

Zyte API is an HTTP API with JSON-encoded requests and responses that can be used with any HTTP client software, and we provide code examples for many different technologies, including Zyte API client software.

You can also use Zyte API from the Zyte dashboard, so you can easily test Zyte API requests, e.g. to calculate costs.

Zyte API client software#

Zyte maintains the following solutions that make using Zyte API easier:

Code examples#

The Zyte API usage documentation features code examples with different software stacks.

Select a software stack from the tabs below to learn how to install and configure the requirements to run code examples for that software stack:

C# code examples use C# 9.0.

To run C# code examples, install:

CLI code examples feature curl and other command-line tools.

To run CLI code examples, install:

  • curl, for requests.

    Note

    curl comes pre-installed in many operating systems.

  • jq, for JSON parsing.

  • base64, for base64 encoding and decoding.

    • On Windows, you can use chocolatey to install GNU Core Utilities, which includes a base64 command-line application.

    • macOS comes with a base64 command-line application pre-installed.

    • Most Linux distributions come with GNU Core Utilities pre-installed, or make it easy to install it. GNU Core Utilities includes a base64 command-line application.

  • xmllint, for HTML parsing.

    • On Windows, install libxml2, which provides xmllint.

    • macOS comes with xmllint pre-installed.

    • Most Linux distributions make it easy to install libxml2, which provides xmllint.

  • xargs, for parallelization.

    • On Windows, you can use chocolatey to install GNU findutils, which includes a xargs command-line application.

    • macOS comes with a xargs command-line application pre-installed.

    • Most Linux distributions come with GNU findutils pre-installed, or make it easy to install it. GNU findutils includes a xargs command-line application.

CLI (best) code examples feature the command-line interface of python-zyte-api, the official Python client of Zyte API, along with other command-line tools.

To run CLI (best) code examples, install:

  • jq, for JSON parsing.

  • base64, for base64 encoding and decoding.

    • On Windows, you can use chocolatey to install GNU Core Utilities, which includes a base64 command-line application.

    • macOS comes with a base64 command-line application pre-installed.

    • Most Linux distributions come with GNU Core Utilities pre-installed, or make it easy to install it. GNU Core Utilities includes a base64 command-line application.

  • xmllint, for HTML parsing.

    • On Windows, install libxml2, which provides xmllint.

    • macOS comes with xmllint pre-installed.

    • Most Linux distributions make it easy to install libxml2, which provides xmllint.

  • xargs, for parallelization.

    • On Windows, you can use chocolatey to install GNU findutils, which includes a xargs command-line application.

    • macOS comes with a xargs command-line application pre-installed.

    • Most Linux distributions come with GNU findutils pre-installed, or make it easy to install it. GNU findutils includes a xargs command-line application.

Java code examples use Java SE 8.

To run Java code examples, install:

JS code examples use JavaScript.

To run JS code examples, install:

PHP code examples use PHP 7.4.

To run PHP code examples, install:

Python code examples use Python 3.

To run Python code examples, install:

Python (best) code examples feature the asyncio API of python-zyte-api, the official Python client of Zyte API.

To run Python (best) code examples, install:

Scrapy code examples feature Scrapy with the scrapy-zyte-api plugin configured in transparent mode.

To run Scrapy code examples, install:

After installing scrapy-zyte-api, you must also configure it in your Scrapy project, and enable its transparent mode, following the upstream configuration instructions.

Tip

The Zyte API tutorial covers installing and configuring the requirements for Scrapy code examples.

Authorization#

Zyte API uses HTTP Basic authentication.

Use your API key as user name, and leave the password field empty.

Set the Authorization header:

var apiKey = "YOUR_API_KEY";
var bytes = Encoding.GetEncoding("ISO-8859-1").GetBytes(apiKey + ":");
var auth = System.Convert.ToBase64String(bytes);
client.DefaultRequestHeaders.Add("Authorization", "Basic " + auth);
curl --user YOUR_API_KEY: 

Define the ZYTE_API_KEY environment variable with your API key.

Alternatively, pass your API key with the --api-key option:

zyte-api --api-key YOUR_API_KEY 
String API_KEY = "YOUR_API_KEY";
String auth = API_KEY + ":";
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
String authHeader = "Basic " + encodedAuth;
request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);

Use the auth parameter of request config:

axios.post(url, data, { auth: { username: 'YOUR_API_KEY' } })
<?php

$client->request(, [
    'auth' => ['YOUR_API_KEY', ''],
]);

Use the auth keyword argument:

requests.post(..., auth=('YOUR_API_KEY', ''), ...)

Define the ZYTE_API_KEY environment variable with your API key.

Alternatively, pass your API key with the api_key keyword parameter to your AsyncClient object:

AsyncClient(api_key='YOUR_API_KEY')

Define the ZYTE_API_KEY environment variable with your API key.

Alternatively, set the ZYTE_API_KEY Scrapy setting with your API key:

settings.py#
ZYTE_API_KEY = 'YOUR_API_KEY'