1. Add your key
Create your key on the API key page (it is shown once). On the same page, under Webhook signing secret, click Reveal and copy thewhsec_… secret. Add both to your server’s environment, and to .env for development:
.env
Video model:
videos/models.py
python manage.py makemigrations && python manage.py migrate.
2. A small client
A400 (a bad link), 401 (a wrong key) or 402 (balance too low) raises ImportlyError with the API’s message. A webhook’s result fields sit in data itself, while the status endpoint nests them under result, so save_result takes the job and its result separately:
videos/importly.py
3. Start the job from a view
"mode": "auto" uses the video’s captions and falls back to speech-to-text when it has none. wait: True holds the request open for up to 30 seconds, so a transcript from captions usually comes back in this one call and is saved straight away. Anything still queued or running finishes later through the webhook. maxCostDollars caps what one link can cost:
videos/views.py
POST /import with importly_kind="import". It returns a job ID straight away, and the webhook brings the mediaUrl:
webhookUrl must be a public https:// address, so set SITE_URL (for example https://your-app.example) in your settings. In local development, leave webhookUrl out and run the command in step 5 to fetch results.
4. The webhook view
Importly sends onePOST when the job finishes. Check the Importly-Signature header against the raw request.body before you trust it: parsing the JSON first changes the bytes and the signature won’t match. Django’s CSRF check would reject the request, so the view is csrf_exempt; the signature does that job here:
videos/views.py
videos/urls.py
importly_result has text, and data.segments with start and end times in seconds. A finished import’s has mediaUrl, a link to the file that’s valid for 7 days: copy it to your storage if you keep it, or connect your bucket once and import with store: true (Save to your bucket). See Webhooks for every payload.
5. Catch missed webhooks
Each job gets one webhook delivery and no retries, so a deploy or a brief outage can miss one. This command asks the status endpoint about every job that has been pending for more than two minutes:videos/management/commands/check_importly_jobs.py
crontab
Notes
A caption transcript costs $0.003; speech-to-text is billed per minute, and downloads by size. See Transcripts, Downloads and Pricing.SOURCE_THROTTLED and LIVE_NOT_SUPPORTED are the failure codes that can work on a later attempt (a site that is busy for now, or a stream that is still live). For those, start the job again later; every other failure code is final. See Media unavailable and Source throttled.
POST /import allows 240 requests per hour per key, and an account can have 50 imports queued or running at once. For hundreds of links, see Batch imports.
A youtube.com/playlist?list=… link is rejected with PLAYLIST_NOT_SUPPORTED. Create one Video per video instead.