OCR Native Integration API v3

Quick Links:

  • Download Postman Collection
  • API Docs

Getting Started:

  1. Account: First you need to get an account. Contact our sales team at partners@chekin.io and they will create an account for you with an email and password
  2. Token: Use your email & password to get a token using our API:
    					

    POST https://a.chekin.io/api/v3/api-token-auth/
    {
    	"email": "your@user",
    	"password": "yourpassword"
    }
    Response:
    {
    	"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiN2JkMzU4NzEyYzJiNDY3ODllM2Y3ZjY1Y2UyM2FlYjgiLCJ1c2VybmFtZSI6Im1hcmlhbm9AY2hla2luLmlvIiwiZXhwIjoxNTcxMjU2OTA2LCJvcmlnX2lhdCI6MTU3MTI1MzMwNiwiaXNfb2NyX2VuYWJsZSI6ZmFsc2UsImZhY2VfZXh0IjpmYWxzZSwib2NyX3ZpeiI6ZmFsc2UsIm9jcl9iYXJjb2RlcyI6ZmFsc2V9.yEYTAeTs3omjqyX4nkWyIogmWcANn-XkUTz2k220Hlg"
    }
    

    The token expires within 1 hour, but the same endpoint can be called to get a new one.

  3. Headers: Add these headers in all your following requests:
    • Content-Type application/json
    •  Authorization JWT {{your token}}

Use Case #1: Use OCR API to build a native guest data capture service.

  1. Implement a form with a “Scan” button
  2. When the user clicks in the “scan id” button you must turn on the camera and ask the user to place the document in front of the camera, at the side that contains the MRZ code.
  3. When the user press “scan”, then a picture is taken and saved as a base64 encoded image. Then call the OCR API sending the picture, to extract the guest data present in the MRZ code:
    					

    POST https://a.chekin.io/api/v3/ocr/picture/
    {
       "picture_file":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQAB..."
    }
    
    	Response:
    	{
        "id":"e895b58927414b57b072066969ce389a",
       "picture_file":"https://temporary_link_to_the_picture",
       "mrz_detected":false,
       "status":"NEW",
       "type_doc":null,
       "country":null,
       "date_of_birth":null,
       "place_of_birth":null,
       "issue_date":"",
       "expiration_date":null,
       "names":null,
       "surname":null,
       "nationality":null,
       "number":null,
       "sex":null,
       "valid_composite":false,
       "valid_date_of_birth":false,
       "valid_issue_date":false,
       "valid_expiration_date":false,
       "valid_number":false,
       "valid_score":null,
       "created_by":"7bd358712c2b46789e3f7f65ce23
    }
    

    The picture will be processed asynchronously as a transaction. You need to save the id returned in the first call and check check the status between 3-5 seconds later. Once status in COM (Complete) you can do a second call to get the extracted data.

    You should show some popup or spinner while the image is being processed:

  4. Get the data once the scan is complete:
    					

    GET https://a.chekin.io/api/v3/ocr/data/e895b58927414b57b072066969ce389a/
    Response:
    {
       "id":"7567a74cf3e045eebb79b0b375de1fd7",
       "picture_file":"https://a_temporary_link_to_the_document_file",
       "mrz_detected":true,
       "status":"COM",
       "type_doc":"I",
       "country":"PL",
       "date_of_birth":"1972-03-30",
       "place_of_birth":null,
       "issue_date":"",
       "expiration_date":"2011-03-09",
       "names":"A1 A",
       "surname":"KOWALSKA",
       "first_surname":"KOWALSKA",
       "second_surname":"",
       "nationality":"PL",
       "number":"ADJ800000",
       "sex":"F",
       "valid_composite":true,
       "valid_date_of_birth":true,
       "valid_issue_date":false,
       "valid_expiration_date":true,
       "valid_number":true,
       "valid_score":100,
       "created_by":"7bd35871-2c2b-4678-9e3f-7f65ce23aeb8"
    }
    

    If status is complete (COM) then the image processing has finished. Otherwise, is status is still in Progress (PRO) you need to check again a few seconds later. Once status is complete you must check field mrz_detected. If mrz_detected is true then the extracted data is valid and it’s returned in the other fields:

    • type_doc
    • country
    • date_of_birth
    • place_of_birth
    • issue_date
    • expiration_date
    • names
    • surname
    • first_surname
    • second_surname
    • nationality
    • number
    • sex

    The API returns all the data present in the MRZ text, so if some fields is null it means that the document doesn’t have that information in the MRZ. This can happen with fields like issue_date or expiration_date in IDs emitted by countries like Germany, France, and a few other cases.

  5. If status is complete you can show a success message and then use the extracted data to fill out the form:
  6. Form filled with data:
  7. The user must have the option to review and edit his data as needed.
  8. If mrz_detected is false or status is error (ERR) then the image processing has failed. The imagen must contain a valid MRZ code, and there are some minimum image quality requirements. you can ask the user to try again taking a new picture.

 

See also:

  • Online CheKin: If you don’t want to develop your own UI, then you can use our this built in product to capture guests data.
Related Articles