# Screenshot API

With this API you can take screenshots of any page. You just have to send a GET request to **`https://api.scrapingdog.com/screenshot`** with the below-given parameters.

Each successful request to this API will cost **`5`** credits.

### Parameters

#### Scrapingdog Parameters

| Parameter                                                       | Description                                                                                              |
| --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| <p>api\_key<br><br><mark style="color:red;">required</mark></p> | <p>Your personal API key. Available on your dashboard.<br><br>Type: <em><strong>String</strong></em></p> |

#### Query Parameters

| Parameter                                                  | Description                                                                                                               |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| <p>url<br><br><mark style="color:red;">required</mark></p> | <p>This is the URL of the page for which you want to take a screenshot.<br><br>Type: <em><strong>String</strong></em></p> |

#### Full Page

| Parameter | Description                                                                                                                                                                      |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| fullPage  | <p>This is a boolean that tells our server to take a full-page screenshot or just the part that is visible without scrolling.<br><br>Type: <em><strong>Boolean</strong></em></p> |

#### Viewport

| Parameter | Description                                                                                               |
| --------- | --------------------------------------------------------------------------------------------------------- |
| width     | <p>This is the width of the browser viewport (pixels).<br><br>Type: <em><strong>String</strong></em></p>  |
| height    | <p>This is the height of the browser viewport (pixels).<br><br>Type: <em><strong>String</strong></em></p> |

#### Wait Until

| Parameter   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| wait\_until | <p>The <code>wait\_until</code> option determines when navigation is considered complete before taking a screenshot or generating HTML/PDF output.<br><br></p><p>By default, <code>wait\_until</code> is set to <code>'domcontentloaded'</code>.</p><p><br>Available options:<br></p><ul><li><strong>load</strong> → resolves when the page’s <code>load</code> event fires</li><li><strong>domcontentloaded</strong> → resolves when the DOM is fully parsed</li><li><strong>networkidle</strong> → resolves when there are no ongoing network requests for at least 500 ms</li></ul><p><br>Type: <em><strong>String</strong></em></p> |

### Format

| Parameter | Description                                                                                                                                                                                                                                                                                                          |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| format    | <p>It is used to get the screenshot in a specific format.<br><br>By default, <code>format</code> is set to <code>'png'</code>.<br><br>Available options:<br></p><ul><li><strong>png</strong> </li><li><strong>jpg</strong> </li><li><strong>webp</strong></li></ul><p><br>Type: <em><strong>String</strong></em></p> |
| quality   | <p>It is used to set the image quality. The allowed range is 0 to 100.<br><br>Default Value: <code>80</code><br><br>Type: String</p>                                                                                                                                                                                 |

### API Example

{% tabs %}
{% tab title="cURL" %}

```bash
curl "https://api.scrapingdog.com/screenshot?api_key=APIKEY&url=https://www.scrapingdog.com"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_key = "APIKEY"
url = "https://api.scrapingdog.com/screenshot"

params = {
    "api_key": api_key,
    "url": "https://www.scrapingdog.com"
}

response = requests.get(url, params=params)

if response.status_code == 200:
    with open("screenshot.png", "wb") as f:
        f.write(response.content)
else:
    print("Failed to capture a screenshot.")

```

{% endtab %}

{% tab title="Nodejs" %}

```javascript
const axios = require('axios');
const fs = require('fs');

const apiKey = 'APIKEY';
const url = 'https://api.scrapingdog.com/screenshot';

const params = {
  api_key: apiKey,
  url: 'https://www.scrapingdog.com',
};

axios
  .get(url, { params, responseType: 'stream' })
  .then((response) => {
    if (response.status === 200) {
      response.data.pipe(fs.createWriteStream('screenshot.png'));
    } else {
      console.error('Failed to capture a screenshot.');
    }
  })
  .catch((error) => {
    console.error('Error:', error.message);
  });

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$apiKey = 'APIKEY';
$url = 'https://api.scrapingdog.com/screenshot';
$targetUrl = 'https://www.scrapingdog.com';

$data = [
    'api_key' => $apiKey,
    'url' => $targetUrl,
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);

if ($response === false) {
    echo 'Error: ' . curl_error($ch);
} else {
    file_put_contents('screenshot.png', $response);
    echo 'Screenshot saved as screenshot.png';
}

curl_close($ch);
?>

```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'

api_key = 'APIKEY'
target_url = 'https://www.scrapingdog.com'

uri = URI('https://api.scrapingdog.com/screenshot')
uri.query = URI.encode_www_form(api_key: api_key, url: target_url)

response = Net::HTTP.get_response(uri)

if response.code.to_i == 200
  # Save the screenshot as screenshot.png
  File.open('screenshot.png', 'wb') do |file|
    file.write(response.body)
  end
  puts "Screenshot saved as screenshot.png"
else
  puts "Error: #{response.code} - #{response.message}"
end

```

{% endtab %}

{% tab title="Java" %}

```java
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class ScreenshotAPI {
    public static void main(String[] args) {
        String apiKey = "APIKEY";
        String apiUrl = "https://api.scrapingdog.com/screenshot";
        String targetUrl = "https://www.scrapingdog.com";

        try {
            HttpClient httpclient = HttpClients.createDefault();
            HttpGet httpGet = new HttpGet(apiUrl + "?api_key=" + apiKey + "&url=" + targetUrl);
            HttpResponse response = httpclient.execute(httpGet);

            if (response.getStatusLine().getStatusCode() == 200) {
                // Get the response stream
                InputStream is = response.getEntity().getContent();

                // Save the screenshot to a file
                FileOutputStream fos = new FileOutputStream("screenshot.png");
                int inByte;
                while ((inByte = is.read()) != -1) {
                    fos.write(inByte);
                }
                is.close();
                fos.close();

                System.out.println("Screenshot saved as screenshot.png");
            } else {
                System.out.println("Error: " + response.getStatusLine().getStatusCode() + " - " + response.getStatusLine().getReasonPhrase());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

```

{% endtab %}
{% endtabs %}

### Response

<figure><img src="/files/byI0NBswzpyohK15RAxE" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scrapingdog.com/screenshot-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
