Introducing DOCSCAN: The Ultimate Global ID Document Scanning API
Tags: webdev, javascript, beginners, react
Published: 2024-07-10 05:46:21

## Revolutionizing eKYC with AI-Powered Document Scanning

In today's fast-paced digital landscape, ensuring the authenticity of user identities is crucial for businesses. Enter PixLab's cutting-edge DOCSCAN API, a powerful tool designed to streamline the eKYC (electronic Know Your Customer) process. This AI-powered platform offers robust ID document scanning and data extraction capabilities, making it a game-changer for developers and businesses alike.

### Key Features of DOCSCAN API

#### Comprehensive Document Support
The DOCSCAN API supports over 11,000 types of ID documents from 197+ countries, including:
- Passports
- ID cards
- Driving licenses
- Visas
- Birth certificates
- Death certificates

No other KYC platform offers such extensive coverage, making DOCSCAN an industry leader.

#### Advanced Features
The API includes highly accurate text scanning and automatic face detection and cropping. This ensures precise extraction of essential details from documents, such as:
- Full name
- Issuing country
- Document number
- Address
- Expiry date

#### Developer-Friendly Integration
DOCSCAN is designed with developers in mind. The single REST API endpoint simplifies the integration process, allowing for quick and easy implementation into any application.

### Versatile Use Cases
DOCSCAN is ideal for various industries and applications, including:
- **KYC (Know Your Customer):** Enhance security across digital platforms.
- **User Verification:** Ensure authenticity in user profiles.
- **Financial Services:** Facilitate international market expansion.
- **Fraud Detection:** Combat identity theft and fraudulent activities.
- **E-commerce:** Prevent chargebacks and combat credit card fraud.
- **Healthcare:** Enhance patient care with secure identity verification.
- **Travel & Hospitality:** Ensure secure, seamless check-in processes for travelers.

### Easy Integration with DOCSCAN API

Integrating the DOCSCAN API into your application is straightforward. Here’s a step-by-step guide to get you started:

#### 1. Get Your API Key
First, you need to sign up at PixLab and generate your API key. This key is essential for authenticating your requests to the DOCSCAN API.

#### 2. Endpoint and Parameters
The primary endpoint for DOCSCAN is `https://api.pixlab.io/docscan`. You can make GET or POST requests to this endpoint, depending on your preference for uploading the document image.

#### 3. Making a Request

Here’s a simple example using JavaScript to scan a passport image:

```javascript
const apiKey = 'YOUR_PIXLAB_API_KEY'; // Replace with your PixLab API Key
const imageUrl = 'http://example.com/passport.png'; // URL of the passport image

const url = `https://api.pixlab.io/docscan?img=${encodeURIComponent(imageUrl)}&type=passport&key=${apiKey}`;

fetch(url)
    .then(response => response.json())
    .then(data => {
        if (data.status !== 200) {
            console.error(data.error);
        } else {
            console.log("Cropped Face URL: " + data.face_url);
            console.log("Extracted Fields: ", data.fields);
        }
    })
    .catch(error => console.error('Error:', error));
```

#### 4. Handling the Response

The API responds with a JSON object containing the scanned information. This includes URLs to the cropped face image and detailed extracted fields like full name, issuing country, document number, and more.

### Additional Code Samples

#### Python

![Python](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xsw6qd22841nt384sm30.png)

#### PHP

![PHP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pu5ikeoe7926kckktr7.png)

#### Ruby

![Rub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uakwrq0k4q83nfgk064o.png)

#### Java
```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject;

public class DocScanExample {
    public static void main(String[] args) {
        try {
            String apiKey = "YOUR_PIXLAB_API_KEY"; // Replace with your PixLab API Key
            String imageUrl = "http://example.com/passport.png"; // URL of the passport image
            String urlStr = "https://api.pixlab.io/docscan?img=" + java.net.URLEncoder.encode(imageUrl, "UTF-8") + "&type=passport&key=" + apiKey;
            URL url = new URL(urlStr);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuilder content = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }
            in.close();
            conn.disconnect();
            JSONObject data = new JSONObject(content.toString());
            if (data.getInt("status") != 200) {
                System.out.println("Error: " + data.getString("error"));
            } else {
                System.out.println("Cropped Face URL: " + data.getString("face_url"));
                System.out.println("Extracted Fields: " + data.getJSONObject("fields").toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

### Comprehensive HTTP Response

The DOCSCAN API endpoint always returns a JSON object. Below are the fields typically included in the response:

- `status`: HTTP status code (200 indicates success).
- `type`: Type of the scanned document.
- `face_url`: URL to the cropped image of the face from the document.
- `mrz_raw_text`: Extracted raw MRZ text (for Passports and Visas only).
- `fields`: A JSON object containing extracted data such as:
  - `fullName`
  - `issuingCountry`
  - `documentNumber`
  - `address`
  - `dateOfBirth`
  - `dateOfExpiry`
  - `sex`
  - `nationality`
  - `issuingDate`
  - `checkDigit`
  - `personalNumber`
  - `finalCheckDigit`
  - `issuingState`
  - `issuingStateCode`
  - `religion`

### How Does the PixLab DocScan Work?

Here’s what happens when you scan a driving license using the DocScan API:

1. The user’s face is detected using the face detect API.
2. After getting the face coordinate, you can crop and extract the image using the image processing API from PixLab.
3. Then, using the DocScan API, PixLab extracts the information about the user.
4. After processing is done, the image is deleted from the server. PixLab doesn’t store any of the images for future reference, ensuring privacy.

PixLab uses PP-OCR, a practical ultra-lightweight OCR system that consists of:
- Text Detection
- Bounding Box Isolation
- Text Recognition

This enables PixLab to generate accurate results by scanning a driver’s license.

### Real-World Example

Suppose you want to verify a user's passport. By using the DOCSCAN API, you can extract all relevant details and store them in your database for future reference. The API also crops the user's face from the passport image, which can be used for profile verification.

#### App.jsx

![App.jsx](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzgb38vpsox5bvq4xeqj.png)

```jsx
// components/DocScanComponent.jsx
import { useState } from 'react';
import axios from 'axios';

const DocScanComponent = () => {
  const [imageUrl, setImageUrl] = useState('');
  const [scanResult, setScanResult] = useState(null);
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState(null);

  const apiKey = 'YOUR_PIXLAB_API_KEY';

  const handleScan = async () => {
    setLoading(true);
    setError(null);

    try {
      const response = await axios.get('https://api.pixlab.io/docscan', {
        params: {
          img: imageUrl,
          type: 'passport',
          key: apiKey,
        },
      });

      if (response.data.status !== 200) {
        setError(response.data.error);
      } else

 {
        setScanResult(response.data);
      }
    } catch (err) {
      setError('Error scanning document');
    } finally {
      setLoading(false);
    }
  };

  return (
    <div>
      <h1>DocScan</h1>
      <input
        type="text"
        placeholder="Enter Image URL"
        value={imageUrl}
        onChange={(e) => setImageUrl(e.target.value)}
      />
      <button onClick={handleScan} disabled={loading}>
        {loading ? 'Scanning...' : 'Scan Document'}
      </button>
      {error && <p style={{ color: 'red' }}>{error}</p>}
      {scanResult && (
        <div>
          <h2>Scan Result:</h2>
          <img src={scanResult.face_url} alt="Cropped Face" />
          <pre>{JSON.stringify(scanResult, null, 2)}</pre>
        </div>
      )}
    </div>
  );
};

export default DocScanComponent;
```
This is a demo passport image. The extracted data using Pixlab Docscan API is listed below.

![Passport](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nibmomftlxsxj7foqz4e.jpg)


### Example Output for a Passport Scan

```
{
  "type": "PASSPORT",
  "face_url": "https://s3.amazonaws.com/media.pixlab.xyz/24p5ba822a00df7F.png",
  "mrz_img_url": "https://s3.amazonaws.com/media.pixlab.xyz/24p5ba822a1e426d.png",
  "mrz_raw_text": "P<UTOERIKSSON<<ANNAXMARIAK<<<<<<<<<<<\nL898962C36UTO7408122F1204159ZE184226B<<<<<16",
  "fields": {
    "fullName": "ERIKSSON ANNA MARIA",
    "issuingCountry": "UTO",
    "documentNumber": "L898902C36",
    "dateOfBirth": "19740812",
    "dateOfExpiry": "20120415",
    "sex": "F",
    "nationality": "UTO"
  }
}
```

### Key Takeaways

- DOCSCAN API supports 11,000+ document types from 197+ countries.
- Easy integration with a single REST API endpoint.
- Advanced AI for accurate text scanning and face detection.
- Streamlines KYC, user onboarding, and fraud prevention processes.
- Compatible with multiple programming languages.

### Conclusion

PixLab's DOCSCAN API offers a comprehensive and efficient solution for eKYC processes. With support for a vast array of documents, advanced scanning features, and a developer-friendly interface, integrating this API into your application can significantly enhance your identity verification processes.

To learn more, explore the [DOCSCAN API documentation](https://api.pixlab.io/docscan) and get started today. Revolutionize your eKYC process with PixLab!

For additional resources, code samples, and community-contributed articles, visit the [PixLab GitHub Repository](https://github.com/PixLab) and join the conversation with fellow developers.