🎉 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 uses a different base URL than the verification session endpoints. Ensure you use the correct URLs to avoid connectivity issues.

Request

Follow these steps to generate a verification PDF report programmatically:

Step 1: Authenticate

Obtain a valid access_token by following the Authentication documentation. This token is required in the Authorization header of your request.

ℹ️

The access_token is valid for 24 hours. You only need to re-authenticate once it expires.

Step 2: Prepare Request Parameters

ParameterTypeRequired?DescriptionExample Value
session_idstringYesThe unique identifier of the session for which to generate a PDF report."11111111-2222-3333-4444-555555555555"

Step 3: Send the Request

Make a GET request to /v1/session/{session_id}/generate-pdf/ with the access token in the Authorization header.

Example Request

GET /v1/session/11111111-2222-3333-4444-555555555555/generate-pdf/ HTTP/1.1
Host: verification.didit.me
Authorization: Bearer {access_token}

Response

The response is a binary PDF file containing detailed information about the verification session.

Response Headers

HeaderValue
Content-Typeapplication/pdf
Content-Dispositionattachment; filename=session_11111111-2222-3333-4444-555555555555.pdf

PDF Content

The generated PDF typically includes:

  • Session information (ID, date, status)
  • User personal details (extracted from documents)
  • Document images (ID, proof of address)
  • Verification results
  • Warnings and alerts
  • Administrative details

Error Handling

Status CodeErrorDescription
401UnauthorizedInvalid or missing access_token.
404Not FoundSession ID not found or invalid.
403ForbiddenNot authorized to access this session's data.

Example Error Response

{
  "detail": "Session not found."
}

PDF Usage Guidelines

  • The PDF is intended for record-keeping and compliance purposes
  • Contains sensitive user information and should be handled accordingly
  • Can be provided to users as proof of verification
  • May be required for regulatory reporting and audits

Consider implementing secure storage for verification PDFs in compliance with relevant data protection regulations like GDPR.

Code Examples

const generateSessionPDF = async (sessionId) => {
  const endpoint = `https://verification.didit.me/v1/session/${sessionId}/generate-pdf/`;
  const token = await getClientToken();
 
  if (!token) {
    console.error('Error fetching client token');
    throw new Error('Authentication failed');
  }
 
  const headers = {
    Authorization: `Bearer ${token.access_token}`,
  };
 
  try {
    const response = await fetch(endpoint, {
      method: 'GET',
      headers,
    });
 
    if (!response.ok) {
      const errorData = await response.json();
      console.error('Error generating PDF:', errorData.detail || errorData.message);
      throw new Error(errorData.detail || 'Failed to generate PDF');
    }
 
    // 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`;
    document.body.appendChild(a);
    a.click();
 
    // Cleanup
    window.URL.revokeObjectURL(url);
    document.body.removeChild(a);
 
    return true;
  } catch (err) {
    console.error('Error:', err);
    throw err;
  }
};
import requests
import os
 
def generate_session_pdf(session_id):
    """
    Generate a PDF report for a verification session and save it to file.
 
    Args:
        session_id (str): The ID of the verification session.
 
    Returns:
        str: The path to the saved PDF file or None if an error occurred.
    """
    url = f"https://verification.didit.me/v1/session/{session_id}/generate-pdf/"
    token = get_client_token()  # Implement this function based on auth documentation
 
    if not token:
        print("Error: Failed to authenticate")
        return None
 
    headers = {
        "Authorization": f"Bearer {token['access_token']}"
    }
 
    try:
        response = requests.get(url, headers=headers, stream=True)
        response.raise_for_status()
 
        # Get the filename from the Content-Disposition header or use a default
        filename = f"session_{session_id}.pdf"
        content_disposition = response.headers.get('Content-Disposition')
        if content_disposition and 'filename=' in content_disposition:
            filename = content_disposition.split('filename=')[1].strip('"')
 
        # Save the PDF to a file
        file_path = os.path.join(os.getcwd(), filename)
        with open(file_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
 
        print(f"PDF saved to {file_path}")
        return file_path
 
    except requests.RequestException as e:
        print(f"Error generating PDF: {e}")
        # Try to get the error message from the response
        try:
            error_detail = e.response.json().get('detail', str(e))
            print(f"Server returned: {error_detail}")
        except:
            pass
        return None

Server-side Implementation (Node.js)

const fs = require('fs');
const axios = require('axios');
 
async function generateAndSaveSessionPDF(sessionId, outputPath) {
  try {
    const token = await getClientToken();
 
    if (!token) {
      throw new Error('Authentication failed');
    }
 
    const response = await axios({
      method: 'get',
      url: `https://verification.didit.me/v1/session/${sessionId}/generate-pdf/`,
      headers: {
        'Authorization': `Bearer ${token.access_token}`
      },
      responseType: 'arraybuffer'
    });
 
    // Save the PDF to a file
    const outputFilePath = outputPath || `./session_${sessionId}.pdf`;
    fs.writeFileSync(outputFilePath, response.data);
 
    console.log(`PDF saved to ${outputFilePath}`);
    return outputFilePath;
  } catch (error) {
    console.error('Error generating or saving PDF:', error.message);
    if (error.response) {
      try {
        // Try to parse the error response
        const errorData = JSON.parse(error.response.data.toString());
        console.error('Server error:', errorData.detail || errorData.message);
      } catch (e) {
        console.error('Server returned a non-JSON error response');
      }
    }
    throw error;
  }
}