> 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/moroccan-documents-ocr/moroccan-driving-license.md).

# Moroccan Driving License

***

This API provides Data Extraction for Moroccan Driving License documents.

## &#x20;<mark style="color:blue;">Moroccan Driving License 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="146">Name</th><th width="81.4000244140625">Type</th><th width="298.4000244140625">Description</th><th>Notes</th></tr></thead><tbody><tr><td>document_type</td><td>string</td><td>mar_driver_license</td><td></td></tr><tr><td>data</td><td>object</td><td><p>Object containing the parameters below:<br><code>{</code> <br> <code>"img": &#x3C;base64 str>,</code> <br><code>"bundle_key": &#x3C;str>,</code><br><code>"lang":&#x3C;str></code></p><p><code>}</code></p></td><td>Please note that<code>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" %}

```python
{
    "result": {
        "first_name": {
            "arabic": <string>,
            "latin": <string>
        },
        "last_name": {
            "arabic": <string>,
            "latin": <string>
        },
        "issue_city": {
            "arabic": <string>,
            "latin": <string>
        },
        "issue_place_v2_license": {
            "arabic": <string>,
            "latin": <string>
        },
        "birth_place": {
            "arabic": <string>,
            "latin": <string>
        },
        "issue_date": <string>,
        "expiry_date": <string>,
        "birth_date": <string>,
        "issue_place_v1_license": <string>,
        "code": <string>,
        "id_num": <string>,
        "card_num": <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 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_driver_license', 
    'data':
    {   
        'img': <'passport_base_64_img'>
        '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 %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://valify.gitbook.io/documentation/apis/moroccan-documents-ocr/moroccan-driving-license.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
