Here’s a complete example of polling for batch PDF status:
Node.js
Python
Copy
async function checkBatchStatus(batchRequestId) { const maxAttempts = 60; // Poll for up to 5 minutes (60 * 5 seconds) let attempts = 0; while (attempts < maxAttempts) { const response = await fetch( `https://api.pdfnoodle.com/v1/pdf/batch/status/${batchRequestId}`, { method: "GET", headers: { Authorization: "Bearer pdfnoodle_api_123456789", }, } ); const result = await response.json(); if (result.status === "SUCCESS" || result.status === "PARTIAL_SUCCESS") { return result; } if (result.status === "FAILED") { throw new Error("All PDFs in the batch failed to generate"); } // Wait 5 seconds before checking again await new Promise((resolve) => setTimeout(resolve, 5000)); attempts++; } throw new Error("Batch PDF generation timed out");}
Copy
import requestsimport timedef check_batch_status(batch_request_id): max_attempts = 60 # Poll for up to 5 minutes (60 * 5 seconds) attempts = 0 while attempts < max_attempts: response = requests.get( f'https://api.pdfnoodle.com/v1/pdf/batch/status/{batch_request_id}', headers={ 'Authorization': 'Bearer pdfnoodle_api_123456789' } ) result = response.json() if result['status'] in ['SUCCESS', 'PARTIAL_SUCCESS']: return result if result['status'] == 'FAILED': raise Exception('All PDFs in the batch failed to generate') # Wait 5 seconds before checking again time.sleep(5) attempts += 1 raise Exception('Batch PDF generation timed out')
If you want to check on the status of a specific PDF within the batch, you can use the Get PDF Status endpoint with the individual requestId from the results array.