const API_URL = 'https://api.olostep.com/v1'
// Paso 1: Crear URL de subida con 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
// Paso 2: Prepara datos JSON batch (formato válido para el endpoint /v1/batches)
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)
})
// Paso 3: Completa la subida
const completeRes = await fetch(`${API_URL}/files/${fileId}/complete`, {
method: 'POST',
headers: { 'Authorization': 'Bearer <YOUR_API_KEY>' }
})
const fileInfo = await completeRes.json()
console.log(`Archivo batch subido con éxito: ${fileInfo.id}`)
console.log(`Tamaño del archivo: ${fileInfo.bytes} bytes`)
console.log(`Propósito: ${fileInfo.purpose}`)