This tutorial follows one tender from "documents not downloaded" to "I can read page 12". The snippets use the api helper from the quickstart.
1. Trigger the download
curl -s -X POST "$KOSMOBIDS_BASE_URL/tenders/$TENDER_ID/documents/download" \
-H "x-api-key: $KOSMOBIDS_API_KEY" | jq
Possible outcomes:
| HTTP | scheduled |
Meaning |
|---|---|---|
202 |
true |
A download workflow started. |
200 |
false |
A download is already running, or there was nothing to download. |
404 |
— | The tender, its source tender ID, or its document record is missing. |
The trigger is safe to repeat while a download is running: it returns 200 and does not start a second workflow.
2. Wait for the files
Poll the file list. Downloads can take minutes to hours, and some portals yield no files.
async function waitForFiles(tenderId: string, timeoutMs = 60 * 60_000) {
const started = Date.now();
let delay = 5_000;
while (Date.now() - started < timeoutMs) {
const files = await api<{ files: Array<{ id: string; filename: string }> }>(
`/tenders/${tenderId}/files`,
);
if (files.files.length > 0) return files;
await new Promise((resolve) => setTimeout(resolve, delay));
delay = Math.min(delay * 2, 60_000);
}
throw new Error('Timed out waiting for tender files');
}
{
"data": {
"files": [
{ "id": "uploaded-file-id", "filename": "specification.pdf" }
]
},
"error": null
}
Files appearing means the download finished, not that OCR is done. OCR runs afterwards: poll the same endpoint until a row's documentStatus is processed, then keep that row's fileId for step 4.
3. Download the original files
Stream an individual file, or fetch all files as one zip:
curl -L "$KOSMOBIDS_BASE_URL/files/$UPLOADED_FILE_ID/download" \
-H "x-api-key: $KOSMOBIDS_API_KEY" \
-o specification.pdf
curl -L "$KOSMOBIDS_BASE_URL/tenders/$TENDER_ID/files/zip" \
-H "x-api-key: $KOSMOBIDS_API_KEY" \
-o tender-documents.zip
The API streams the tender's precomputed zip when one exists and builds the archive on demand when it does not, so the request can wait while the archive is assembled. Both responses are binary, not the JSON envelope. The Content-Type and Content-Disposition headers describe the file.
4. Read the processed document
The uploaded file ID (the row's id) is not the processed document ID (fileId). The processed document is created by OCR and indexing. Read it from GET /tenders/:tenderId/files once the row's documentStatus is processed; analysis references also carry it. Then:
curl -s "$KOSMOBIDS_BASE_URL/documents/$PROCESSED_FILE_ID" \
-H "x-api-key: $KOSMOBIDS_API_KEY" | jq
{
"data": {
"id": "processed-document-id",
"filename": "specification.pdf",
"status": "processed",
"pageCount": 120,
"contentSummary": "The tender covers a multi-year cloud migration...",
"tableOfContents": [
{ "title": "Eligibility", "summary": "Mandatory requirements.", "pageRange": [1, 4] }
]
},
"error": null
}
Use tableOfContents to find a section, then read only the pages you need.
5. Read page text and regions
curl -s "$KOSMOBIDS_BASE_URL/documents/$PROCESSED_FILE_ID/pages?startPage=10&endPage=12" \
-H "x-api-key: $KOSMOBIDS_API_KEY" | jq
{
"data": {
"pages": [
{
"pageNumber": 12,
"status": "processed",
"content": "…OCR text…",
"pageWidth": 2480,
"pageHeight": 3508,
"uploadedFileId": "page-image-id",
"regions": [
{ "index": 0, "content": "2.1 Eligibility", "bbox_2d": [120, 340, 1800, 410] }
]
}
]
},
"error": null
}
- Supply both
startPageandendPage; omit both to read every page. bbox_2dis[x1, y1, x2, y2]in page-image pixels.uploadedFileIdis the page image; stream it with/files/:uploadedFileId/download.
6. Read headers for navigation
curl -s "$KOSMOBIDS_BASE_URL/documents/$PROCESSED_FILE_ID/headers" \
-H "x-api-key: $KOSMOBIDS_API_KEY" | jq
{
"data": {
"headers": [
{ "pageNumber": 3, "title": "2.1 Eligibility", "label": "paragraph_title", "category": "text_block" }
]
},
"error": null
}
Failure handling
| Symptom | What to do |
|---|---|
404 on download |
The tender has no source tender or no document record. Stop retrying. |
200 with scheduled: false |
A download is already running or there is nothing to download. Poll the file list. |
| No files after a long wait | The portal may not expose documents. Treat the tender as document-less and continue with the tender metadata. |
404 on /documents/:fileId/pages |
No document exists for that ID, or the ID is the wrong one (an uploaded id instead of the row's fileId). A document that exists but is still processing returns 200 with empty pages; check /documents/:fileId status. |
500 while streaming |
Retry the download once; if it persists, contact support. |