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
Parameter | Type | Required? | Description | Example Value |
---|---|---|---|---|
|
| Yes | The 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
Header | Value |
---|---|
Content-Type | application/pdf |
Content-Disposition | attachment; 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 Code | Error | Description |
---|---|---|
401 | Unauthorized | Invalid or missing access_token. |
404 | Not Found | Session ID not found or invalid. |
403 | Forbidden | Not 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;
}
};
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;
}
}