# Quick Guide

***

## 1) Prerequisites

* **Authentication token:** This can be generated through our auth API.&#x20;
* **Bundle Key:** This will be found in the email you received upon signup.

## *2) Setting up*

### *2.1) Generate a token*

*for more details about OAuth Token go to:*[oauth-token](https://valify.gitbook.io/documentation/apis/oauth-token "mention")

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

1. Download the JSON file from here.&#x20;

{% file src="<https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FtOU0hJUmxfbbuPWBtLpR%2FAccess%20Token.postman_collection?alt=media&token=5027129b-471e-4e9b-8cf3-73af73f82b91>" %}

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%2FC9Pn2tf2QzWCZ6btzRhu%2FScreenshot%202024-01-17%20133422.png?alt=media&#x26;token=c64486a9-ee52-44d7-bbb5-cc44440cf3e6" alt=""><figcaption></figcaption></figure>

3. Drop the JSON file.&#x20;

<figure><img src="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FVxrzgOyHbizYe0ZiGKy2%2F2.png?alt=media&#x26;token=76ad026c-4a55-467b-b968-0d92cc3dd380" alt=""><figcaption></figcaption></figure>

4. Choose "Access Token" as shown below and update the "Body" with your credentials then click "Send".&#x20;

   <figure><img src="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FT45dSGjjCnzH0Hoh6xuV%2F3.png?alt=media&#x26;token=1dc42582-9f19-43d7-b244-6b2288f72328" alt=""><figcaption></figcaption></figure>
5. The access token will be shown in the response.&#x20;

<figure><img src="https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FeaMXM2ca0QKfIqmkqFJP%2F4.png?alt=media&#x26;token=9ade7b0f-36ef-4ce6-bcd5-2ff307e4b320" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Please note that the token can be used within 10 minutes and needs to be generated again.&#x20;
{% endhint %}
{% endtab %}

{% tab title="Python" %}
Copy this code and put your credentials to easily generate the access token.

```python
r = requests.post("https://www.valifystage.com/api/o/token/",
        data={
            'username': '<username>', 
            'password': '<password>', 
            'client_id': '<client id>',  
            'client_secret': '<client secret>', 
            'grant_type': 'password' #default value no need to change
        }
    )

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

{% endtab %}
{% endtabs %}

## *3) Hit your first API request!*

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

1. Download the JSON file from here.

{% file src="<https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2Fp5OjPhWKCnpM8tGfyzWS%2FValify%20-%20EGY%20NID%20OCR%20v1.4.postman_collection?alt=media&token=48443cd2-b078-4617-b70a-ea052e30f6b1>" %}

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%2FC9Pn2tf2QzWCZ6btzRhu%2FScreenshot%202024-01-17%20133422.png?alt=media&#x26;token=c64486a9-ee52-44d7-bbb5-cc44440cf3e6" 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%2Fo3FmHNsUyKOAFrWAowyV%2Fimage.png?alt=media&#x26;token=549b5453-1613-49be-838a-1ae14811e01b" 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%2FDzkILhYhQqAp90PD2if9%2Focr%20BEFOORE.png?alt=media&#x26;token=7a9f1c28-8d41-46d5-8067-7260d1cfa76d" 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%2FoHJe4SviRhU4lBGQ5u1j%2FNID.png?alt=media&#x26;token=ca61bffb-d8da-44d6-aee0-9e61f469fab1" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Python" %}
{% code title="NID OCR " 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.4/ocr/",
        json=data,
        headers={'Authorization': 'Bearer %s' % token}
    )          

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

{% endcode %}

{% hint style="info" %}
Please check all the comments in the code and replace with the required data.
{% endhint %}
{% endtab %}
{% endtabs %}
