Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save symisc/1907c7dcbc1c03791b22c4ac9323f211 to your computer and use it in GitHub Desktop.

Select an option

Save symisc/1907c7dcbc1c03791b22c4ac9323f211 to your computer and use it in GitHub Desktop.
Scan over 11K ID Documents from over 197 countries using the PixLab DOCSCAN API Endpoint documented at: https://pixlab.io/id-scan-api/docscan
=begin
* Scan over 11K ID Documents from over 197 countries using the PixLab DOCSCAN API Endpoint
* documented at: https://pixlab.io/id-scan-api/docscan
*
* Refer to the official documentation at: https://pixlab.io/id-scan-api/docscan
* for the API reference guide and more code samples.
=end
require 'net/http'
require 'uri'
require 'json'
api_key = 'PIXLAB_API_KEY' # Replace with your PixLab API Key from https://console.pixlab.io
image_url = 'http://i.stack.imgur.com/oJY2K.png' # ID document input image sample
# Target API Endpoint located at: https://api.pixlab.io/docscan
# Documentation of the DOCSCAN API Endpoint is located at: https://pixlab.io/id-scan-api/docscan
uri = URI("https://api.pixlab.io/docscan?img=#{URI.encode_www_form_component(image_url)}&type=passport&key=#{api_key}")
begin
# Make the GET Request. You can switch to POST if you prefer uploading the image directly.
response = Net::HTTP.get(uri)
reply = JSON.parse(response)
if reply['status'] != 200
puts "Error: #{reply['error']}"
else
# Dump everything the scanner returned to us
puts JSON.pretty_generate(reply)
# Typical JSON output using specimen data:
#
# {
# "type": "DRIVER LICENSE",
# "face_url": false,
# "fields": {
# "documentNumber": "99 999 999",
# "fullName": "JANICE ANN SAMPLE",
# "issuingDate": "2016-10-05",
# "expiryDate": "2020-08-05",
# "dateOfBirth": "1969-08-04",
# "address": "123 MAIN STREET APT. 1 HARRISBURG, PA 17101-0000",
# "issuingCountry": "USA",
# "gender": "female",
# "issuingState": "PA"
# },
# "status": 200
# }
end
rescue StandardError => e
puts "An error occurred: #{e.message}"
end
@symisc

symisc commented Nov 28, 2024

Copy link
Copy Markdown
Author

Scan over 11K ID Documents from over 197 countries using the PixLab DOCSCAN API Endpoint documented at: https://pixlab.io/id-scan-api/docscan

PixLab recommend that you connect your AWS S3 bucket via the dashboard at https://console.pixlab.io/ so that any extracted face or MRZ crop is automatically stored on your S3 bucket rather than the PixLab one. This feature should give you full control over your analyzed media files.

Refer to the official documentation at: https://pixlab.io/id-scan-api/docscan for the API reference guide and more code samples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment