Skip to main content
If your Laravel app takes video or podcast links, the media job is the one that breaks once it runs on a server: sites block datacenter IPs, and many videos have no captions to read. Call Importly from a queued job instead. It returns the transcript, a download link for the file, or the video’s details, for links from YouTube, TikTok, Instagram, X, podcasts and 1,000+ other sites. Long imports can take a few minutes, so don’t hold a worker for them. One job starts the Importly job and stores its ID, and a second job checks the status and dispatches itself again 20 seconds later until it’s done. A retry only ever re-runs the check, so it never starts the job twice. The code uses Laravel’s Http client and plain ShouldQueue jobs, so it runs on the database, Redis or SQS queue drivers and under Horizon.

1. Add your key

Create your key on the API key page (it is shown once). Add it as IMPORTLY_API_KEY to .env and to the environment your app and queue workers run in:
.env
Read it through config/services.php, so it still works after php artisan config:cache:
config/services.php
The jobs below save to a Video model with url, importly_job_id, importly_status, importly_result (json, cast to array) and importly_error columns:
database/migrations/xxxx_create_videos_table.php

2. A small client

A 429 throws ImportlyException with the retryAfter the API sent, and a 5xx throws it with 30 seconds. A 400 (a bad link), 401 (a wrong key) or 402 (balance too low) won’t change on a retry, so it throws with retryAfter set to null and the job fails:
app/Exceptions/ImportlyException.php
app/Services/Importly.php

3. The jobs

A shared trait waits for retryAfter on a 429 or 5xx, up to 5 tries, fails straight away on anything else, and saves the outcome:
app/Jobs/Concerns/TracksImportlyJob.php
"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 from the first call and is saved straight away:
app/Jobs/TranscribeLink.php
POST /import returns a job ID straight away:
app/Jobs/ImportLink.php
Anything still queued or running goes to the check job:
app/Jobs/CheckImportlyJob.php
A finished transcript’s 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 disk with Storage::put() if you keep it, or connect your bucket once and import with store: true (Save to your bucket). A caption transcript costs $0.003; speech-to-text is billed per minute, and maxCostDollars caps what one link can cost. See Transcripts and Downloads.

Run it

Dispatch the job from your controller once the record is saved:
app/Http/Controllers/VideoController.php
Then run a worker with php artisan queue:work (or Horizon). The sync driver runs the 20-second checks back to back without waiting, so use a real queue driver outside tests.

Webhooks

Prefer a webhook? Add 'webhookUrl' => route('importly.webhook') to the body of /import or /transcribe (it must be a public https:// URL), and keep the check job as a fallback: each job gets one delivery and no retries. Your signing secret is on the API key page under Webhook signing secret; add it as IMPORTLY_WEBHOOK_SECRET. The controller checks the Importly-Signature header against the raw body from $request->getContent(), rejects requests older than 5 minutes, and accepts a match against any v1 (there are two for 24 hours after you rotate the secret). It then reads the job from the API with the check job, and skips jobs the check job already finished:
app/Http/Controllers/ImportlyWebhookController.php
routes/web.php
Importly can’t send a CSRF token, so leave the route out of CSRF checks:
bootstrap/app.php
See Verify signatures for the header format.

Notes

SOURCE_THROTTLED and LIVE_NOT_SUPPORTED are the failure codes that can work on a later attempt (a stream that is still live, or a site that is busy for now). For those, dispatch TranscribeLink or ImportLink 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. Status endpoints allow 3,600 requests per hour per job type; a check every 20 seconds is 180 an hour for each job in progress, so about 20 jobs can poll at once. Put these jobs on their own queue (->onQueue('media')) and run a limited number of workers for it. For hundreds of links, see Batch imports. A youtube.com/playlist?list=… link is rejected with PLAYLIST_NOT_SUPPORTED. Dispatch one job per video instead.