Skip to main content

Batches API

API for managing pipeline batch executions.

Overview

A Batch represents a single execution instance of a pipeline. When a batch is created, the pipeline runs in the Prefect workflow engine, and you can monitor the progress of each step.

Endpoints

POST /api/v1/batches/{pipeline_id}

Executes a pipeline batch.

Path Parameters

ParameterTypeRequiredDescription
pipeline_idstringYesPipeline ID

Query Parameters

ParameterTypeRequiredDescription
pipeline_versionstringNoExecute specific version (default: latest)

Response

200 OK

{
"item": "batch-xyz789"
}
FieldTypeDescription
itemstringCreated batch ID

GET /api/v1/batches/{pipeline_id}

Retrieves the latest batch status of a pipeline.

Path Parameters

ParameterTypeRequiredDescription
pipeline_idstringYesPipeline ID

Response

200 OK

{
"id": "batch-xyz789",
"name": "sales-pipeline",
"deployment": "run-pipeline/sales-pipeline",
"state": {
"state": "running",
"steps": {
"extract": {
"state": "success",
"offsets": {"partition_0": 1000}
},
"transform": {
"state": "running",
"offsets": {"partition_0": 500}
},
"load": {
"state": "pending",
"offsets": {}
}
}
}
}

Batch State Values

StateDescription
stopStopped
runningRunning
pendingPending
scheduledScheduled

Step State Values

StateDescription
noneNot started
pendingPending
runningRunning
successSuccess
failedFailed

GET /api/v1/batches/{pipeline_id}/{batch_id}

Retrieves the status of a specific batch.

Path Parameters

ParameterTypeRequiredDescription
pipeline_idstringYesPipeline ID
batch_idstringYesBatch ID

Response

Same format as GET /api/v1/batches/{pipeline_id}.


GET /api/v1/batches/{pipeline_id}/

Retrieves all batch lists for a pipeline.

Path Parameters

ParameterTypeRequiredDescription
pipeline_idstringYesPipeline ID

Query Parameters

ParameterTypeDefaultDescription
limitinteger100Maximum number of items to retrieve
tokenstring-Pagination token

Response

200 OK

{
"items": {
"batch-xyz789": "{...batch json...}",
"batch-abc123": "{...batch json...}"
},
"token": "next-page-token"
}

PUT /api/v1/batches/{pipeline_id}/{batch_id}/stop

Stops a running batch.

Path Parameters

ParameterTypeRequiredDescription
pipeline_idstringYesPipeline ID
batch_idstringYesBatch ID

Response

200 OK

{
"message": "Batch stopped successfully"
}

DELETE /api/v1/batches/{pipeline_id}/{batch_id}

Deletes a batch. Running batches are stopped first.

Path Parameters

ParameterTypeRequiredDescription
pipeline_idstringYesPipeline ID
batch_idstringYesBatch ID

Response

200 OK

{
"message": "Batch deleted successfully"
}

Usage Examples

cURL

# Execute batch
curl -X POST https://api.dhub.io/api/v1/batches/pipeline-abc123 \
-H "Authorization: Bearer <access_token>"

# Get latest batch status
curl https://api.dhub.io/api/v1/batches/pipeline-abc123 \
-H "Authorization: Bearer <access_token>"

# Stop batch
curl -X PUT https://api.dhub.io/api/v1/batches/pipeline-abc123/batch-xyz789/stop \
-H "Authorization: Bearer <access_token>"

# Delete batch
curl -X DELETE https://api.dhub.io/api/v1/batches/pipeline-abc123/batch-xyz789 \
-H "Authorization: Bearer <access_token>"

Batch Status Polling

async function pollBatchStatus(pipelineId, batchId, interval = 5000) {
while (true) {
const response = await fetch(`/api/v1/batches/${pipelineId}/${batchId}`, {
headers: { 'Authorization': `Bearer ${accessToken}` }
});
const batch = await response.json();

console.log(`Batch state: ${batch.state.state}`);

// Check step states
for (const [stepName, stepState] of Object.entries(batch.state.steps)) {
console.log(` ${stepName}: ${stepState.state}`);
}

// Check if completed
const allDone = Object.values(batch.state.steps)
.every(s => s.state === 'success' || s.state === 'failed');

if (allDone || batch.state.state === 'stop') {
console.log('Batch completed');
break;
}

await new Promise(resolve => setTimeout(resolve, interval));
}
}