# Introduction

## Microshot API Reference

The Microshot API is organized around [REST](http://en.wikipedia.org/wiki/Representational_State_Transfer). Our API has predictable resource-oriented URLs,  uses JSON format for request bodies, returns [JSON-encoded](http://www.json.org/) responses, and uses standard HTTP response codes, authentication, and verbs.

### REST API <a href="#rest-api" id="rest-api"></a>

The Microshot API adheres to [REST](http://en.wikipedia.org/wiki/Representational_State_Transfer) conventions. Our API communicates in JSON format and uses [API tokens](/authentication) to authenticate requests.&#x20;

The server-side REST API is available at:

```
https://api.microshot.io
```

By default, the API returns the screenshot image data directly, along with the relevant headers. However, if you set the  [response\_type](/endpoints/screenshot#capture-screenshot) parameter to `json` the response will be in the form of a JSON which contains a link to the generated screenshot hosted on our CDN.

All the screenshots are cached for 24 hours. It means that after that time, the image won't be available anymore on our CDN. Cached screenshots don't count in your monthly quota.

## Start exploring API

Dive a little deeper and start exploring our API endpoints to get an idea of everything that's possible with the API:

{% content-ref url="/pages/vjJT7UyJuytsimMofWvg" %}
[Endpoints](/endpoints/screenshot)
{% endcontent-ref %}


# Authentication

The Microshot API uses API keys to authenticate requests.

API keys are managed via the Microshot interface. To view or create one, navigate to your [API Keys](https://app.microshot.io/api-keys):

<figure><img src="https://3871769754-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMUvIeDTAWvQfa5JFlA38%2Fuploads%2FGsr8B9GVegtggeru3ZAP%2Fapikeysms.png?alt=media&amp;token=fb78794f-0b13-43eb-ab3f-5c3115c5b4cc" alt=""><figcaption></figcaption></figure>

API requests without authentication will fail.

Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, etc.

Add your API key to the `x-api-key` header to access the API endpoints.

```bash
# example cURL request
curl -H 'x-api-key: <your_api_key>' https://api.microshot.io/v1/screenshot?url=https://github.com
```


# Screenshot

## Capture Screenshot

## Capture screenshot

<mark style="color:blue;">`GET`</mark> `https://api.microshot.io/v1/screenshot`

Captures a new screenshot

#### Query Parameters

| Name                                  | Type    | Description                                                                                                                                                                                                                                                                                                                                                           |
| ------------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| url<mark style="color:red;">\*</mark> | string  | The URL of the website for which you want to capture a screenshot. It should be URL encoded and must include the protocol (`http://` or `https://`) to be processed correctly.                                                                                                                                                                                        |
| format                                | string  | <p>Defines the image format to be used. One of <code>png</code>, <code>jpeg</code>, <code>webp</code><em>.</em> </p><p></p><p>Defaults to <code>jpeg</code></p>                                                                                                                                                                                                       |
| quality                               | integer | <p>The quality of the image between <code>0</code> and <code>100</code>. Works only with the <code>jpeg</code> and <code>webp</code> formats. </p><p></p><p>Defaults to <code>80</code></p>                                                                                                                                                                           |
| disable\_ads                          | bool    | <p>Prevent ads from being displayed on the captured screenshot. Block requests from popular ad-networks.</p><p></p><p>Defaults to <code>false</code></p>                                                                                                                                                                                                              |
| full\_page                            | bool    | <p>It captures a full scrollable page screenshot.</p><p></p><p>Defaults to <code>false</code></p>                                                                                                                                                                                                                                                                     |
| response\_type                        | bool    | <p>The type of response to return. Can be either <code>image</code> or <code>json</code>.</p><p></p><p>When the <code>json</code> type is used, the JSON response with the link to the screenshot hosted on our CDN is returned.</p><p></p><p>When the <code>image</code> type is used, the binary image is returned.</p><p></p><p>Defaults to <code>image</code></p> |
| width                                 | integer | <p>The width of the viewport to use (in pixels).</p><p></p><p>Defaults to <code>1920</code></p>                                                                                                                                                                                                                                                                       |
| height                                | integer | <p>The height of the viewport to use (in pixels).</p><p></p><p>Defaults to <code>1080</code></p>                                                                                                                                                                                                                                                                      |
| hide\_cookie\_banners                 | bool    | <p>Prevent cookie banners and popups from being displayed.</p><p></p><p>Defaults to <code>false</code></p>                                                                                                                                                                                                                                                            |
| animations                            | bool    | <p>Enables/disables CSS <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/animation">animations</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transition">transitions</a>.</p><p></p><p>Defaults to <code>true</code></p>                                                                                                                 |

{% tabs %}
{% tab title="500: Internal Server Error Unable to capture the screenshot." %}

```javascript
{
    message: "Unreachable host."
}
```

{% endtab %}

{% tab title="429: Too Many Requests Too many requests hit the API too quickly. We recommend an exponential backoff of your requests" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="422: Unprocessable Entity Invalid arguments" %}

<pre class="language-json"><code class="lang-json">{
    message: "Invalid arguments",
<strong>    errors: {
</strong>        url: [
            "The URL should be provided."
        ]
    }
}
</code></pre>

{% endtab %}

{% tab title="200: OK Screenshot successfully captured" %}

```json
{
    url: "https://cdn.microshot.io/XC31L2VqiGPO3SGGBSjJ-mgqa9SDX8fiWm0Wmyi5MrYFtuW5ubyl0vPxGD11m2lHusOGJEZOIc5xmk-w.jpeg"
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid or revoked API key" %}

```json
{
    type: "https://tools.ietf.org/html/rfc2616#section-10",
    title: "An error occurred",
    status: 401,
    detail: "Unauthorized"
}
```

{% endtab %}
{% endtabs %}


