# Face Match (Two Images)

***

```markdown
You can use the Face Match service by providing two face images to be compared.
The result will be "True" if similar or "False" if not.
```

## <mark style="color:blue;">Face Match (Two Images)</mark>

<mark style="color:green;">`POST`</mark> `https://valifystage.com/api/v1.1/face/match/`

#### Headers

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

#### Request&#x20;

| Name                                   | Type   | Description                                                                                                                                                                                                                              |
| -------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| data<mark style="color:red;">\*</mark> | object | <p>Request details</p><p><code>{</code> <br>  <code>first\_img: \<base64 str>,</code></p><p> <code>second\_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': {
        'is_similar': '<bool>', 
         'confidence': '<float>'
     }, 
     'transaction_id': '<str>', 
     '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 %}

***

## Integration

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

1. Download the JSON file.

{% file src="<https://641522850-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmzgYXwSfAFtfOUAPpKlY%2Fuploads%2FlrgFrE2vnmhvFGhk6ply%2FDocumentation%20-%20Face%20Match%20(2%20images)%20(v1).postman_collection?alt=media&token=6b63679c-9778-4bad-96cf-0f775776445e>" %}
Face Match (2 images)
{% endfile %}

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&#x26;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&#x26;token=f6a020e6-b467-436f-8ec7-cc48a4c73070" alt=""><figcaption></figcaption></figure>

4. Click on "Face Match" 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%2FLBlr7TQF1zE4CwLLnAcp%2Fauthfm.png?alt=media&#x26;token=704722d4-3a3e-4b88-aaa8-67c3288a8fe9" alt=""><figcaption></figcaption></figure>

4. Click on "Face Match" then "Body" and fill in the required fields then click on "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%2FkHD02E0MVVUFimfKWwxt%2FFaceMatch.png?alt=media&#x26;token=4470a35b-5c53-4831-80c1-dca6aa191398" alt=""><figcaption></figcaption></figure>
{% endtab %}

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

first_img = base64_encode('<image path>')
second_img = base64_encode('<image path>')
token = '<token>'
data = {
        'first_img': first_img,
        'second_img': second_img,
        'bundle_key': '<bundle key>', # Place your bundle key here
        'lang': '<lang>' # optional
}

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

{% endtab %}
{% endtabs %}
