# 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="<https://content.gitbook.com/content/mzgYXwSfAFtfOUAPpKlY/blobs/rNrLXV4guZr7m8jp0rvk/Documentation%20-%20OCR%20(passport)%20(v1).postman_collection.json>" %}
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 ""

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 %}
