const API_URL = 'https://api.olostep.com/v1'
// Step 1: Create upload URL with purpose="batch"
const createRes = await fetch(`${API_URL}/files`, {
method: 'POST',
headers: { 'Authorization': 'Bearer <YOUR_API_KEY>', 'Content-Type': 'application/json' },
body: JSON.stringify({ filename: 'batch-items.json', purpose: 'batch' })
})
const uploadData = await createRes.json()
const fileId = uploadData.id
const uploadUrl = uploadData.upload_url
// Step 2: Prepare batch JSON data (valid format for /v1/batches endpoint)
const batchData = {
items: [
{ custom_id: 'item-1', url: 'https://www.google.com/search?q=stripe&gl=us&hl=en' },
{ custom_id: 'item-2', url: 'https://www.google.com/search?q=paddle&gl=us&hl=en' },
{ custom_id: 'item-3', url: 'https://www.google.com/search?q=payment+gateway&gl=us&hl=en' }
],
parser: { id: '@olostep/google-search' },
country: 'US'
}
await fetch(uploadUrl, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(batchData)
})
// Step 3: Complete the upload
const completeRes = await fetch(`${API_URL}/files/${fileId}/complete`, {
method: 'POST',
headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
})
const fileInfo = await completeRes.json()
console.log(`Batch file uploaded successfully: ${fileInfo.id}`)
console.log(`File size: ${fileInfo.bytes} bytes`)
console.log(`Purpose: ${fileInfo.purpose}`)