🎉 Unlimited Free KYC - Forever!!

Identity Verification
API Reference
Generate PDF

Generating a Verification PDF Report

To generate a PDF report containing the verification session results, you can call the /v1/session/{sessionId}/generate-pdf/ endpoint.

  • Base URL: https://verification.didit.me
  • Endpoint: /v1/session/{sessionId}/generate-pdf/
  • Method: GET
  • Authentication: Client Token (Bearer Token)
⚠ī¸

The Authentication endpoint has a different Base URL than the verification session endpoints. Ensure you are using the correct URLs for each endpoint to avoid connectivity issues.

Request

To generate a verification PDF report programmatically, follow these steps:

Authenticate

To obtain the access_token, refer to the Authentication documentation page.

ℹī¸

The access_token is valid for a limited time (x minutes), so you do not need to authenticate for every request until the token expires.

Select Desired Parameters

  • session_id: Unique identifier for the session.

Generate PDF Report

Use the following request format to generate the PDF report:

GET /v1/session/{session_id}/generate-pdf/ HTTP/1.1
Host: verification.didit.me
Content-Type: application/json
Authorization: Bearer {access_token}

Response

Returns a PDF file containing detailed information about the verification session. The response includes appropriate headers for file download.

  • Content-Type: application/pdf
  • Content-Disposition: attachment; filename=session_{session_id}.pdf

Code Example

const generateSessionPDF = async (sessionId) => {
  const endpoint = `${BASE_URL}/v1/session/${sessionId}/generate-pdf/`;
  const token = await getClientToken();
 
  if (!token) {
    console.error('Error fetching client token');
  } else {
    const headers = {
      Authorization: `Bearer ${token.access_token}`,
    };
 
    try {
      const response = await fetch(endpoint, {
        method: 'GET',
        headers,
      });
 
      if (response.ok) {
        // Convert the response to a blob
        const blob = await response.blob();
 
        // Create a download link
        const url = window.URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = `session_${sessionId}.pdf`; // or use the filename from Content-Disposition
        document.body.appendChild(a);
        a.click();
 
        // Cleanup
        window.URL.revokeObjectURL(url);
        document.body.removeChild(a);
 
        return true;
      } else {
        const errorData = await response.json();
        console.error('Error generating PDF:', errorData.message);
        throw new Error(errorData.message);
      }
    } catch (err) {
      console.error('Network error:', err);
      throw err;
    }
  }
};

The code example above shows how to handle the PDF file in a browser environment. For server-side implementations, you'll need to adjust the file handling logic according to your backend framework.

Server-side Example (Node.js)

const fs = require('fs');
 
const generateSessionPDF = async (sessionId) => {
  const endpoint = `${BASE_URL}/v1/session/${sessionId}/generate-pdf/`;
  const token = await getClientToken();
 
  if (!token) {
    console.error('Error fetching client token');
  } else {
    const headers = {
      Authorization: `Bearer ${token.access_token}`,
    };
 
    try {
      const response = await fetch(endpoint, {
        method: 'GET',
        headers,
      });
 
      if (response.ok) {
        // Get the array buffer of the PDF
        const arrayBuffer = await response.arrayBuffer();
 
        // Save the PDF to a file
        const fileName = `session_${sessionId}.pdf`;
        fs.writeFileSync(fileName, Buffer.from(arrayBuffer));
 
        return fileName;
      } else {
        const errorData = await response.json();
        console.error('Error generating PDF:', errorData.message);
        throw new Error(errorData.message);
      }
    } catch (err) {
      console.error('Network error:', err);
      throw err;
    }
  }
};