> 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/egy-nid-ocr-1.md).

# Copy on National ID OCR

This API provides Data Extraction for the Egyptian National ID.

## Egyptian National ID OCR

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

| Name                                             | Type   | Description     |
| ------------------------------------------------ | ------ | --------------- |
| document\_type<mark style="color:red;">\*</mark> | string | egy\_nid        |
| data<mark style="color:red;">\*</mark>           | object | Request details |

{% 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>',
    },
    
    "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"
    ],
"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="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&amp;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&amp;token=f6a020e6-b467-436f-8ec7-cc48a4c73070" 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="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FmCtjL8oFHYIotdY6kUky%2Focr%20BEFOORE.png?alt=media&amp;token=e5134642-222f-423e-ba19-a56a403c9044" 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="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FU0FH43LqJqoZGwMElfaL%2FNID.png?alt=media&amp;token=d2a50b35-0adb-46b0-9cf8-dc97324ab408" 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,
        'verify_document':'false',
        'bundle_key': '<bundle key>', # Put your bundle key here
        '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 %}
