cURL
curl --request GET \ --url https://getbill.io/external-api/v1/reports/download/{id} \ --header 'Authorization: <authorization>'
{ "error": false, "message": "Report download information retrieved", "data": { "id": "report_abc123", "filename": "financial_summary_2024_01.pdf", "file_size": 245760, "mime_type": "application/pdf", "download_url": "https://secure-downloads.getbill.io/reports/abc123def456?expires=1706789400&signature=sha256hash", "expires_at": "2024-02-01T12:30:00Z" } }
Get download information for a completed report
reports:read
curl -X GET "/external-api/v1/reports/download/report_abc123" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
false
Show download data
async function downloadReport(reportId, accessToken) { try { // Get download information const infoResponse = await fetch( `/external-api/v1/reports/download/${reportId}`, { headers: { 'Authorization': `Bearer ${accessToken}` } } ); if (!infoResponse.ok) { throw new Error('Failed to get download information'); } const downloadInfo = await infoResponse.json(); // Download the actual file const fileResponse = await fetch(downloadInfo.data.download_url); if (!fileResponse.ok) { throw new Error('Failed to download file'); } // Create blob and download const blob = await fileResponse.blob(); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = downloadInfo.data.filename; document.body.appendChild(a); a.click(); // Cleanup window.URL.revokeObjectURL(url); document.body.removeChild(a); } catch (error) { console.error('Download failed:', error); } }
import requests import os def download_report(report_id, access_token, save_path=None): try: # Get download information info_response = requests.get( f'/external-api/v1/reports/download/{report_id}', headers={'Authorization': f'Bearer {access_token}'} ) info_response.raise_for_status() download_info = info_response.json()['data'] # Download the actual file file_response = requests.get(download_info['download_url']) file_response.raise_for_status() # Save to file filename = save_path or download_info['filename'] with open(filename, 'wb') as f: f.write(file_response.content) print(f'Report downloaded successfully: {filename}') return filename except requests.RequestException as e: print(f'Download failed: {e}') return None
{ "error": true, "message": "Access denied to this report", "code": 403 }