import requests
import json
API_KEY = "<YOUR_API_KEY>"
API_URL = "https://api.olostep.com/v1"
# Step 1: Create upload URL with 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"]
# Step 2: Prepare batch JSON data (valid format for /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()
# Step 3: Complete the 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 file uploaded successfully: {file_info['id']}")
print(f"File size: {file_info['bytes']} bytes")
print(f"Purpose: {file_info['purpose']}")