# National ID OCR

<pre class="language-markdown"><code class="lang-markdown"><strong>This API provides Data Extraction for the Egyptian National ID.
</strong></code></pre>

## <mark style="color:blue;">Egyptian National ID OCR</mark>

<mark style="color:green;">`POST`</mark> `https://<base-url>/api/v1.5/ocr/`

#### Headers

| Name                                             | Type   | Description            |
| ------------------------------------------------ | ------ | ---------------------- |
| Content-Type<mark style="color:red;">\*</mark>   | string | application/json       |
| Authentication<mark style="color:red;">\*</mark> | string | Bearer \<access-token> |

#### Request&#x20;

| Name                                             | Type   | Description                                                                                                                                                                                                                            |
| ------------------------------------------------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| document\_type<mark style="color:red;">\*</mark> | string | egy\_nid                                                                                                                                                                                                                               |
| data<mark style="color:red;">\*</mark>           | object | <p>Request details</p><p><code>{</code> <br>  <code>front\_img: \<base64 str>,</code></p><p> <code>back\_img: \<base64 str>,</code><br>  <code>bundle\_key: \<str>,</code><br>  <code>lang: \<str></code><br><code>}</code></p><p></p> |

#### Status Codes

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

```python
{
    "result": 
    {
        "first_name": '<string>',
        "full_name": '<string>',
        "street": '<string>',
        "front_nid": '<string>',
        "serial_number": '<string>',
        "back_nid":'<string>',
        "release_date": '<string>',
        "gender": '<string>',
        "marital_status": '<string>'
        "profession": '<string>',
        "religion":'<string>',
        "husband_name": '<string>',
        "date_of_birth": '<string>',
        "age":'<int>',
        "birth_governarate": '<string>',
        "police_station": '<string'>,
        "governorate": '<string>',
        "expiry_date": '<string>',
    },
    
     "advanced_confidence": 
    {
        "is_face_fraud_detected": '<boolean>'
    },
  
   "document_verification_plus": 
   {
        "expired": '<boolean>',
        "front_data_validity": '<boolean>',
        "back_data_validity": '<boolean>',
        "is_front_greyscale": '<boolean>',
        "is_back_greyscale": '<boolean>'
    },
    
   "profession_analysis": 
   {
        "workplace": '<string>',
        "profession_categorization": '<string>',
    },
    
    "document_liveness":
    {
        "is_front_document_live": '<boolean>',
        "front_document_format": '<string>',
        "is_back_document_live": '<boolean>',
        "back_document_format": '<string>'
    },
    
    "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: Internal Server Error" %}

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

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Note: The object below is one of the parameters included in the request as mentioned in the previous section&#x20;
{% endhint %}

<details>

<summary>data &#x3C;object></summary>

```json
"bundle_key": "<bundle_key>",
"extras":[
            "advanced_confidence",
            "document_verification_plus",
            "profession_analysis"
            "document_liveness"
    ],
"front_img": "<base64-encoded-image",
"back_img": "<base64-encoded-image",
"lang": "<string>"
```

</details>

***

## Integration&#x20;

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

1. Download the JSON file from here.

{% file src="/files/6AnpaVElvmUJ6eXoNTZu" %}

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 "Egy NID OCR" then click on "Authorization" and replace the \<access token> field with your access token and then click on "Body".

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

5. After clicking on "Body", fill in the required fields then click Send.

{% hint style="info" %}
Please note that the front and back images should be converted to base 64 format. This can be done via an online tool; <https://base64.guru/converter/encode/image/jpg>&#x20;
{% endhint %}

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

{% tab title="🐍Python 3" %}
{% code overflow="wrap" fullWidth="true" %}

```python
import requests
import base64
import json

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 ""

front_image = base64_encode('<image path>')#Put your front image path here
back_image = base64_encode('<image path>')#Put your back image path here
token = "<token>"

r = requests.post("https://www.valifystage.com/api/o/token/",
        data={
            'username': '<username>', #Put all your credentials in those fields
            'password': '<password', 
            'client_id': '<client_id>',  
            'client_secret': '<client_secret>', 
            'grant_type': 'password'
        }
    )

token=r.json()['access_token']

data = {
    'document_type': 'egy_nid', 
    'data':
    {   
        'front_img': front_image,
        'back_img': back_image,
        'bundle_key': '<bundle key>', # Put your bundle key here
        'extras': ["document_verification_plus", "advanced_confidence"]
        'lang': '<lang>' 
    }
}

r = requests.post("https://valifystage.com/api/v1.5/ocr/",
        json=data,
        headers={'Authorization': 'Bearer %s' % token}
    )          

result = r.json()
print(result)
```

{% endcode %}
{% 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/kyc/kyc-documents/egy-nid-ocr.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.
