import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
# Passaggio 1: Crea URL di caricamento con purpose="batch"
create_response = requests.post(
f"{API_URL}/files",
headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
json={"filename": "batch-items.json", "purpose": "batch"}
)
upload_data = create_response.json()
file_id = upload_data["id"]
upload_url = upload_data["upload_url"]
# Passaggio 2: Prepara i dati JSON batch (formato valido per l'endpoint /v1/batches)
batch_data = {
"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"
}
upload_response = requests.put(
upload_url,
data=json.dumps(batch_data),
headers={"Content-Type": "application/json"}
)
upload_response.raise_for_status()
# Passaggio 3: Completa il caricamento
complete_response = requests.post(
f"{API_URL}/files/{file_id}/complete",
headers={"Authorization": f"Bearer {API_KEY}"}
)
file_info = complete_response.json()
print(f"File batch caricato con successo: {file_info['id']}")
print(f"Dimensione file: {file_info['bytes']} bytes")
print(f"Scopo: {file_info['purpose']}")