Skip to main content
Version: 3.2.0

INE (Mexican National Identification)

POST

  https://api.apptenticate.com/api/v3.2/ocr/


Authentication

Use your JWT obtained from the authentication process to make requests to this endpoint.

The response will be 401 unauthorized if the JWT is expired. In this case you will have to obtain a new JWT.


This endpoint receives all requests directed to the Apptenticate OCR microservice that allows data extraction from Mexican identification documents (INE/IFE). The service processes both the front and back of the document, extracting information from OCR on the front and the MRZ (Machine Readable Zone) on the back. In the end, the ID Reader microservice will return a JSON with the extracted data if the operation was successful, or the appropriate error if it was not.

NOTE

• The response may be 401 unauthorized if the JWT token must be refreshed.

• Images sent in jpg format must not exceed 2MB.

• If you want to obtain the transaction ID in the response, you must indicate "return_id": "True" in the JSON of the request.

• You must specify in the request the document type using the "document_type" parameter, which must take the value "id_mexico".

• If you want to validate the frontside and backside data, you must indicate "validate_sides": True in the JSON of the request.

Request structure - method: POST

Path: api/ocr/

Payload for base request:

Payload: {
'frontside': Image of the front of the document,
'backside': Image of the back of the document,
'document_type': 'mexican_id',
} // (where images are .jpg files)

If you want to obtain the transaction ID:

Payload: {
'frontside': Image of the front of the document,
'backside': Image of the back of the document,
'document_type': 'mexican_id',
'return_id': True
} // (where images are .jpg files)

If you want to improve the precision of the life test:

Payload: {
'frontside': Image of the front of the document,
'backside': Image of the back of the document,
'document_type': 'mexican_id',
'device': 'IOS', // Devices: IOS, ANDROID or DESKTOP
} // (where images are .jpg files)

Request examples

Python

# JWT Token
header = { 'Authorization': 'Bearer {}'.format(token) }

# Payload for base request
data = {'document_type': 'id_mexico'}
files = {
'frontside': imagen_1.jpg,
'backside': imagen_2.jpg,
} # Where images are .jpg files

# If you want to obtain the transaction ID:
data = {'document_type': 'id_mexico', 'return_id': True}
files = {
'frontside': imagen_1.jpg,
'backside': imagen_2.jpg,
} # Where images are .jpg files

# If you want to validate both sides of the document:
data = {
'document_type': 'mexican_id',
'validate_sides': True,
}
files = {
'frontside': imagen_1.jpg,
'backside': imagen_2.jpg,
} # Where images are .jpg files

# Sending the request
response = requests.post(
apptenticate_url,
data=data,
files=files,
headers=header
)
response = json.loads(response.content)

Response structure

Data extracted from frontside (OCR):

The service extracts the following fields from the front of the document:

  • name: Citizen's first names
  • surname: Citizen's last names
  • address: Registered address
  • CURP: Unique Population Registry Code (18 alphanumeric characters)
  • elector_key: Elector Key (18 alphanumeric characters)
  • validity_period: Document validity period
  • date_of_birth: Date of birth
  • document_type: Document type (INE)
  • section: Electoral section
  • gender: Gender (H/M)
  • emission_number: Registration/emission year

Data extracted from backside (MRZ):

The service extracts the following fields from the back of the document:

  • document_type: Document type (INE)
  • country_code: Country code (MEX)
  • document_number: Identification number
  • birth_date: Date of birth in DD-MM-YYYY format
  • gender: Gender (Male/Female)
  • expiration_date: Expiration date in YYYY-MM-DD format
  • name: First names extracted from the MRZ
  • surname: Last names extracted from the MRZ

• Base response (without side validation):

Response format: JSON
{
"document_type": "INE",
"country_code": "MEX",
"document_number": "1234567890123",
"citizen_id": "137438414",
"cic": "345636022",
"birth_date": "15-03-1990",
"gender": "Male",
"expiration_date": "2025-12-31",
"surname": "GARCIA LOPEZ",
"name": "JUAN CARLOS",
"valid": true
}

• Response with transaction ID:

Response format: JSON
{
"document_type": "INE",
"country_code": "MEX",
"document_number": "1234567890123",
"citizen_id": "137438414",
"cic": "345636022",
"birth_date": "15-03-1990",
"gender": "Male",
"expiration_date": "2025-12-31",
"surname": "GARCIA LOPEZ",
"name": "JUAN CARLOS",
"valid": true
"id": 281234
}

• Response with side validation (validate_sides: True):

Response format: JSON
{
"backside": {
"document_type": "INE",
"country_code": "MEX",
"document_number": "1234567890123",
"citizen_id": "137438414",
"cic": "345636022",
"birth_date": "15-03-1990",
"gender": "Male",
"expiration_date": "2025-12-31",
"name": "JUAN CARLOS",
"surname": "GARCIA LOPEZ"
},
"frontside": {
"name": "JUAN CARLOS",
"surname": "GARCIA LOPEZ",
"address": "CALLE REFORMA 123 COL CENTRO",
"CURP": "GALJ900315HDFRPN01",
"elector_key": "GLRJNC90031512H400",
"validity_period": "2024-2034",
"date_of_birth": "15-03-1990",
"document_type": "INE",
"section": "1234",
"gender": "Male",
"emission_number": "12"
},
"matches_percentage": 85.5,
"match": true,
"valid": true
}

• In the case of a failed OCR:

Response format: JSON
{
"error_code": 806,
"error": "No se pudo extraer la metadata del documento",
"valid": false
}

Automatic validations

The service performs the following automatic validations:

CURP Validation (Unique Population Registry Code):

  • Must have exactly 18 characters
  • First 4 characters must be letters
  • Next 6 characters must be numbers (date of birth)
  • Position 10 must be H or M (gender)
  • Next 2 characters must be letters (state)
  • Next 3 characters must be letters (consonants)
  • Last 2 characters must be alphanumeric

Elector Key Validation:

  • Must have exactly 18 alphanumeric characters
  • First 6 characters must be letters
  • Next 6 characters must be numbers (date)
  • Validation of valid federal entity code (00-32)
  • Position 14 must be H or M (gender)
  • Last 3 characters must be alphanumeric

MRZ Validation:

  • Document must be TD1 type (3 lines)
  • Country code must be "MEX"
  • Structure validation according to ICAO standard

Error codes

CodeMessage
800Sent file could not be processed correctly.
802Could not process the date of birth.
803Could not process the gender.
804Could not process the expiration date.
806Could not extract document metadata.
807Could not extract names from the document.
808Could not extract the identification number from the document.
809The "frontside" was not sent in the request.
810The "backside" was not sent in the request.
814Could not extract the MRZ from the document.
816The document does not match the one specified in the parameters.
819Could not extract the CURP from the document.