Batch Downloads with Webhooks
Submit multiple video download jobs at once and receive webhook notifications when each one finishes — no polling required.
Overview
Instead of polling, you can pass a webhook_url when submitting a job. HuntAPI will POST the result to your URL the moment the download is ready. This playbook shows how to:
- Submit a batch of jobs with a webhook URL
- Receive and verify the webhook payload
Prerequisites
- A HuntAPI key — get one at app.huntapi.com
- A publicly reachable HTTP endpoint (use ngrok for local testing)
- Install dependencies for your language:
pip install requests flaskSteps
Submit a batch of jobs with a webhook URL
Pass your publicly accessible endpoint as webhook_url. Each job is independent; HuntAPI will call the webhook when it finishes.
import requests
API_KEY = "YOUR_API_KEY"
WEBHOOK_URL = "https://yourserver.example.com/webhooks/huntapi"
URLS = [
"https://www.youtube.com/watch?v=VIDEO_ID_1",
"https://www.youtube.com/watch?v=VIDEO_ID_2",
"https://www.youtube.com/watch?v=VIDEO_ID_3",
]
job_ids = []
for video_url in URLS:
r = requests.get(
"https://api.huntapi.com/v1/video/download",
headers={"x-api-key": API_KEY},
params={"url": video_url, "quality": "best", "webhook_url": WEBHOOK_URL},
)
job_id = r.json()["job_id"]
job_ids.append(job_id)
print(f"Submitted: {job_id}")
print(f"\n{len(job_ids)} jobs submitted. Waiting for webhooks...")Build a webhook receiver
HuntAPI will POST a JSON body to your endpoint with job_id, status, and download_url when the job completes.
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/webhooks/huntapi", methods=["POST"])
def huntapi_webhook():
payload = request.get_json()
job_id = payload.get("job_id")
status = payload.get("status")
download_url = payload.get("download_url")
print(f"Webhook received — Job: {job_id}, Status: {status}")
if status == "done" and download_url:
# Trigger your download or further processing here
print(f" Download URL: {download_url}")
return jsonify({"received": True}), 200
if __name__ == "__main__":
app.run(port=3000)Test locally with ngrok
During development, use ngrok to expose your local server to the internet so HuntAPI can reach your webhook.
# Start your local server first, then:
ngrok http 3000Copy the generated https://xxxx.ngrok.io URL and use it as your webhook_url parameter.
Your webhook endpoint must return a 2xx status code within 10 seconds, otherwise HuntAPI will retry the delivery. Make heavy processing asynchronous and acknowledge the webhook immediately.