# Passport

***

```markdown
This API provides Data Extraction for Travel Passport documents, particularly the 
identity page containing the individual's information.
```

The "validity" metric in this API's successful response indicates the validity of the data extracted from the document.

## <mark style="color:blue;">Passport OCR</mark>

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

#### Headers

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

#### Request Body

| Name           | Type   | Description                                                                                                                                                                                         |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| document\_type | string | passport                                                                                                                                                                                            |
| data           | object | <p>Object containing the parameters below:<br><code>{</code> <br>  <code>img: \<base64 str>,</code><br>  <code>bundle\_key: \<str>,</code><br>  <code>lang: \<str></code><br><code>}</code><br></p> |

#### Status Codes

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

```python
{
    "result": {
        "expiration_date": '<string>',
        "date_of_birth": '<string>',
        "name": '<string>',
        "nationality":'<string>',
        "surname": '<string>',
        "passport_number": '<string>',
        "sex": '<string>',
        "type": '<string>',
        "validity": '<int>'
    },
    "transaction_id": '<string>',
    "trials_remaining": '<int>'
}
```

{% 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/-MY9acoPM-CvC6gJuWLW" %}
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 ""

image = base64_encode('<image path>')
token = "<token>" # Place your token here
data = {
    'document_type': 'passport', 
    'data':
    {
        'img': image,
        'bundle_key': '<bundle key>', # Place your bundle key here
        'lang': '<str>' # optional
    }
}

r = requests.post("https://valifystage.com/api/v1.1/ocr/",
        json=data,
        headers={'Authorization': 'Bearer %s' % token}
    )
                      
print(r.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-1.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.
