# 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="<https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2F6VY9LOzrUIqI0uDwjIkk%2FID%20Cropper%20API.postman_collection.json?alt=media&token=fffe4df6-af2c-4cfb-a07e-a1ae2994cc07>" %}
Passport OCR
{% endfile %}

2. Open Postman and click on Import.

   <figure><img src="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FQCA8mOwCZmLtlswqUFMt%2FScreenshot%202024-01-17%20133422.png?alt=media&#x26;token=d547d1f3-e4f4-4923-92aa-a95d15833bbe" alt=""><figcaption></figcaption></figure>

   3. Drop the JSON file.

   <figure><img src="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FuqV6eXGTNlzp4ztDmrva%2F2.png?alt=media&#x26;token=f6a020e6-b467-436f-8ec7-cc48a4c73070" 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="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FqQjsL6oqDoeNVmkOrmWe%2Fpassport.png?alt=media&#x26;token=e3d621d7-f52e-46f7-8863-a13991ca4c94" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2Fs8cPmHmlC6pt0gNYhuJe%2Fpassport2.png?alt=media&#x26;token=5da4f81e-390c-44fc-89d5-bb286a37472a" 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: 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://valify.gitbook.io/documentation/apis/passport.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.
