import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
# Stap 1: Maak upload-URL aan met 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"]
# Stap 2: Bereid batch JSON-data voor (geldige indeling voor /v1/batches endpoint)
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()
# Stap 3: Voltooi de upload
complete_response = requests.post(
f"{API_URL}/files/{file_id}/complete",
headers={"Authorization": f"Bearer {API_KEY}"}
)
file_info = complete_response.json()
print(f"Batch bestand succesvol geüpload: {file_info['id']}")
print(f"Bestandsgrootte: {file_info['bytes']} bytes")
print(f"Doel: {file_info['purpose']}")