# Face Match (Image & Transaction ID)

***

```markdown
Instead of sending two images, you can provide one face image and the Transaction ID 
of a valid Data Extraction service transaction, so we can compare the face from this 
transaction's document with the face image provided. 
```

The transaction ID can be found in the data extraction API response.

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 (Image & Transaction ID)</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 Body

| 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>transaction\_id: \<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%2Fbue3BVZAf6Ift90LzPRP%2FDocumentation%20-%20Face%20Match%20(image%20%26%20transaction%20ID)%20(v1).postman_collection?alt=media&token=9fd88eda-2cfc-4851-a382-691dc4138fd7>" %}
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%2FlcmSGYuv0oq0ht3oIziM%2Fauthfm.png?alt=media&#x26;token=0534c697-60b2-412e-8557-60f48704055a" alt=""><figcaption></figcaption></figure>

5. 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 ""

face_img = base64_encode('<image path>')
token = '<token>'
data = {
        'first_img': face_img,
        'transaction_id': '<transaction id>', # Place the transaction ID here
        'bundle_key': '<bundle key>', # Place your bundle key here
        'lang': 'en'
}

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

{% endtab %}
{% endtabs %}
