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 asIMPORTLY_API_KEY to .env and to the environment your app and queue workers run in:
.env
config/services.php, so it still works after php artisan config:cache:
config/services.php
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
A429 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 forretryAfter 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
queued or running goes to the check job:
app/Jobs/CheckImportlyJob.php
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
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
bootstrap/app.php
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.