Face · eKYC Core

Index faces

POST/v1/index_faces_sync

Indexes the face in an image into a collection so it can later be retrieved by Search faces, and returns the indexed image id.

Request

MethodPOST
Path/v1/index_faces_sync
Content-Typeapplication/json
Auth requiredYes — HMAC signing

Clients can provide image data to the TrustVision API by specifying the ID the image by using upload API, or by sending the image data as base64-encoded text.

NameTypeRequiredDescription
imageImageDataRequiredimage to index face. Should use image has the face. if use TS SDK, use last frontal image
enable_update_metadataboolOptionalAllow image.metadata to be updated.
collectionstringOptionalindex faces to this collection. case-sensitive
typeintOptionaltype of collection
file_namestringOptionalfile name of the image, at most 255 characters. Required when file-name tracking is enabled for your client; see The file_name parameter
  • If you use base64, label and metadata, omit parameter id.
  • If you use id (result id is returned from Upload Image API), omit parameter base64, label and metadata.
  • If not set collection, default collection will be used.
JSON
{
    "image": {
        "id": string,
        "base64": string,
        "label": string,
        "metadata": string_json,
    },
    "enable_update_metadata": bool,
    "collection": string,
    "type": int,
    "file_name": string
}

Which type's parameter contains value:

valuedescription
3Matching Selfie vs Selfie

The file_name parameter

file_name lets you track an indexed image by your own file name, and later delete its faces by that name with Delete faces. It is read only when TrustVision has enabled file-name tracking for your client or access key (setting require_file_name); otherwise the field is ignored. Contact your TrustVision Account Manager to enable it.

When file-name tracking is enabled:

  • Every call needs a file name: the top-level file_name, or a file_name key inside image.metadata. If you send both, they must be equal. The name is stored on the image as image.metadata.file_name.
  • file_name is at most 255 characters. It is case-sensitive and is not trimmed. Use printable characters only — no tab, line feed, carriage return or NUL.
  • A file name can be live at most once for your client, across all collections. A name is live once a call indexed at least one face under it, until its faces are deleted with Delete faces. Sending a live name again is rejected with 400 file_name is already indexed, before the image is uploaded.
  • An image in which no face is found is not tracked, so its file name stays free and can be sent again. A name whose faces were deleted can be indexed again; the image gets a new image.id.
  • With image.id (an already uploaded image), also send enable_update_metadata: true, so the file name can be stored on the image.
  • A call that sends collections instead of collection is not tracked by its file name: the name is not checked for duplicates, and the image cannot be deleted by name.
  • Do not send the same file_name in two calls at the same time: both may pass the duplicate check.
JSON
{
    "image": {
        "base64": "<base64 of the image>",
        "label": "portrait"
    },
    "file_name": "IMG_20261101_0000123.jpg",
    "collection": "my_collection"
}

Sample request

curl -X POST \
'<BASE_URL>/v1/index_faces_sync' \
-H 'Authorization: TV <YOUR ACCESS KEY>:<CREATED SIGNATURE>' \
-H 'X-TV-Timestamp: 2019-04-21T18:00:15+07:00' \
-H 'Content-Type: application/json' \
-d \
'
{
    "image": {
        "id": "a4facba3-334b-41fb-97e3-4766cb70ae29"
    }
}
'

Response

data.image.id is the image whose face was indexed. In case the request processing has been finished, the HTTP status code will be 200, and the data.status is either "success" or "failure" depending on whether the request has been successfully processed or not.

JSON
{
    "data": {
        "request_id": string,
        "image": {
          "id": string, // id of the image
          "transformed_image_id": string // optional, just in case the image is transformed
        },
        "status": string, // "success" or "failure"
    },
    "errors": [
        {
            "code": string,
            "message": string,
            "detail": {
                "field": string, // optional, which parameter is invalid.
                ... // any other information that can be useful for client
            },
        },
        ... // other errors
    ]
}

A successful index comes back like this:

JSON
{
    "data": {
        "status": "success",
        "image": {
          "id": "a4facba3-334b-41fb-97e3-4766cb70ae29"
        },
        "request_id": "dfdef016-e89b-4da4-ae17-5844f909c947"
    }
}

Failure codes

If the data.status is "failure", the "errors" field will tell you why it failed.

In case of any other errors, the data field will be empty, and the server sends one of the following HTTP status codes with an error code:

HTTP codeError codeDescription
400invalid_parameter_exceptionInput parameter violates a constraint.
400request_time_too_skewedThe X-TV-Timestamp header is expired, need a newer one.
401access_denied_exceptionYou are not authorized to perform the action.
404image_not_found_exceptionThe image ID is not found in DB.
404request_not_found_exceptionThe request ID is not found when polling result by id.
408request_timeout_exceptionRequest takes too long to process.
429rate_limit_exceptionThe number of requests exceeded your throughput limit.
500internal_server_errorSome unexpected error occurs while processing the request.

When file-name tracking is enabled for your client, file_name adds these 400 invalid_parameter_exception errors. The message is exact:

messagedetailCause
file_name is required{"field": "file_name"}Neither file_name nor image.metadata.file_name is set.
file_name must be at most 255 characters{"field": "file_name"}The file name is too long.
file_name differs from image.metadata.file_name{"field": "file_name"}file_name and image.metadata.file_name are both set and differ.
image.metadata must be a JSON object to hold file_name{"field": "image.metadata"}file_name is set and image.metadata is not a JSON object.
file_name with image.id requires enable_update_metadata{"field": "file_name"}image.id is used without enable_update_metadata: true.
file_name is already indexed{"field": "file_name"}The file name is live for your client, in any collection. Nothing is stored.

The codes above are the ones documented for this endpoint. Response errors lists the codes for the eKYC Core surface as a whole — the two lists do not match on every endpoint.