# Saudi National ID&#x20;

```markup
This API provides Data Extraction for the Moroccan National ID document.
```

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

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

#### Headers

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

#### Request Body

<table><thead><tr><th width="142.5999755859375">Name</th><th width="71.79998779296875">Type</th><th width="345.199951171875">Description</th><th>Notes</th></tr></thead><tbody><tr><td>document_type</td><td>string</td><td>KSA_nid_ocr</td><td></td></tr><tr><td>data</td><td>object</td><td>Object containing the parameters below:<br><code>{</code> <br><code>"front_img":&#x3C;base64 str>,</code> 

<br><code>"bundle\_key": \<str> ,</code> <br><code>"lang": \<str></code><br><code>}</code></td><td>Please note that <code>front\_img</code> cannot be empty (i.e., missing or an empty string <code>""</code>).</td></tr></tbody></table>

**Status Codes**

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

<pre class="language-python"><code class="lang-python"><strong>{
</strong>  "result": {
    "full_name": {
      "arabic": &#x3C;string>,
      "latin": &#x3C;string>
  },
  "transaction_id": &#x3C;string>,
  "trials_remaining": &#x3C;string>
}
</code></pre>

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

{% tabs %}
{% tab title="🐍Python" %}

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

front_image = base64_encode('<image path>') # Place your front image here
back_image = base64_encode('<image path>') # Place your back image here
token = "<token>" # Place your token here
data = {
    'document_type': 'mar_nid_ocr', 
    'data':
    {   
        'front_img': front_image,
        'back_img': back_image,
        'bundle_key': '<bundle key>', # Place your bundle key here
        'lang': '<str>' # optional, default: en
    }
}

r = requests.post("https://<base-url>/api/v1/ocr/",
        json=data,
        headers={'Authorization': 'Bearer %s' % token}
    )
                      
print(r.json())
```

{% endtab %}
{% endtabs %}
