> For the complete documentation index, see [llms.txt](https://valify.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://valify.gitbook.io/documentation/apis/passport.md).

# ID Cropper

***

The **ID Cropper API** automatically crops ID images to keep only the document itself and remove any surrounding background. Send the image as a Base64 string, and the API detects the ID area, isolates it, and returns a clean, properly cropped version of the document.

## <mark style="color:blue;">ID Cropper</mark>

<mark style="color:green;">`POST`</mark> `https://valifystage.com/api/v1/id_cropper_register`

#### Headers

| Name           | Type   | Description            |
| -------------- | ------ | ---------------------- |
| Content-Type   | string | application/json       |
| Authentication | string | Bearer \<access-token> |

#### Request Body

| Name            | Type   | Description                             |
| --------------- | ------ | --------------------------------------- |
| bundle\_key     | string | A bundle key provided to you by Valify. |
| img             | string | Base64 image that need to be cropped    |
| lang (optional) | string | The error message language              |

#### Status Codes

{% tabs %}
{% tab title="✅ 200 Successful" %}

```python
{
    "data": {
        "img": "<base64_cropped_image>"
    },
    "transaction_id": <str>,
    "trials_remaining": <str>
}
```

{% endtab %}

{% tab title="400 Missing input data" %}

```python
{
    "message": "Bad Request – invalid request received (e.g. missing Bundle key, required parameters or invalid json) | Make sure all the required parameters are included"
}
```

{% endtab %}

{% tab title="401 Invalid bundle key" %}

```python
{
    "message": "Unauthorized – your Bundle key is invalid"
}
```

{% endtab %}

{% tab title="403 Access token error" %}

```python
{
    "message": "Forbidden – specified access_token could not be found"
}
```

{% endtab %}

{% tab title="404 Check the endpoint" %}

```python
{
    "message": "Not Found"
}
```

{% endtab %}

{% tab title="415 The format should be base64" %}

```python
{
    "message": "Unsupported Media Type"
}
```

{% endtab %}

{% tab title="422 Check Valify error codes" %}

```python
{
    "message": "<error-description>",
    "error_code": <valify-error-code>
}
```

{% endtab %}

{% tab title="500 Contact us" %}

```python
{
    "message": "Internal Server Error"
}
```

{% endtab %}
{% endtabs %}

***

## Integration

{% tabs %}
{% tab title="🚀Postman" %}

1. Download the JSON file from here.

{% file src="/files/fPb1E7WMvOmfQikMecCZ" %}
Passport OCR
{% endfile %}

2. Open Postman and click on Import.

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

   3. Drop the JSON file.

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

   4. Click on "Passport" and then click on "Authorization" and replace the \<access token> field with your access token and then click on "Body".

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

5. Click on "Body" then fill in the required data and hit "Send".

<figure><img src="/files/LrV5zgKdKnmL00dcky2d" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="🐍Python 3" %}

```python
import requests
import base64

def base64_encode(file_name):
    with open(file_name, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode()
        return encoded_string
    return ""

# Encode your image
image = base64_encode('<image path>')

token = "<access-token>"  # Place your token here

data = {
    "bundle_key": "<bundle_key>",   # Place your bundle key here
    "img": img,
    "lang": "<str>"  # optional
}

response = requests.post(
    "https://<your-domain>/api/v1/id_cropper/register/",
    json=data,
    headers={
        "Authorization": "Bearer %s" % token,
        "Content-Type": "application/json"
    }
)

print(response.json())
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://valify.gitbook.io/documentation/apis/passport.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
