Skip to Content
Upload

Link videos to your records

Tag each video with your own ID through passthrough, so every webhook and lookup leads straight back to your record.

passthrough is your own ID for a video, such as lesson_42. You set it when you create the upload or import, ClipMux stores it on the video, and it comes back on the video and in every webhook. Your webhook handler finds the record a video belongs to without keeping a map of ClipMux IDs, and without trusting anything else in the body.

Before you start

  • A record in your own database for each video, created before you call ClipMux, with an ID you can send.

Set it

Make the record first, then send its ID as passthrough when you create the upload (POST /v1/uploads) or the import (POST /v1/assets).

// With clipmuxHandler, return it from the upload callback:
async upload(req, { file }) {
  const lesson = new URL(req.url).searchParams.get('lesson')
  return { passthrough: `lesson_${lesson}`, title: file.name }
}

// Or with the client:
const upload = await clipmux.uploads.create({ size, passthrough: 'lesson_42' })

The command lines take it as --passthrough lesson_42.

  • It is a string of up to 255 bytes; a longer one is 400 invalid_request.
  • It is set once, when the video is made. The API has no route to change it later.
  • It isn't unique: ClipMux doesn't stop two videos sharing one, for example when a lesson's video is replaced. Your record decides which video is current.
  • It isn't secret, and it isn't checked. Use an ID, not personal data.

Use it in webhooks

Every webhook body carries the video, and the video carries passthrough:

{ "id": "evt_…", "type": "video.asset.ready", "created_at": "…",
  "data": { "id": "ast_…", "status": "ready", "version": 4, "passthrough": "lesson_42", "…": "…" } }

In your handler, after verifying the signature:

  1. Find the record by data.passthrough. If it isn't one of yours (the dashboard's test event has none), answer 200 and ignore it.
  2. Re-fetch the video with GET /v1/assets/{id}, since the body says that something changed, not what it is now.
  3. Store its status, its playback ID and its version, if the version is at least the one you have.

clipmuxHandler's asset callback does the verifying and re-fetching, so you upsert by asset.passthrough. See Receive webhooks.

Store the video's ID on your record as soon as the upload is created, from asset_id in the answer: you have it before the file arrives.

Find videos by it

GET /v1/assets?passthrough=lesson_42 returns your app's videos with that passthrough, newest first, leaving out deleted ones:

const videos = await clipmux.assets.findByPassthrough('lesson_42')
const latest = videos[0]

This needs assets:read. Use it to repair a record that missed its webhooks, or to check before creating a second upload for the same record.

Check it works

Upload a test file with a passthrough, then look it up:

npx @clipmux/node upload sample.mp4 --passthrough lesson_42
curl -s "https://video.example.com/v1/assets?passthrough=lesson_42" \
  -H "Authorization: Bearer $CLIPMUX_API_KEY" | jq '.data[] | {id, status, passthrough}'

The new video is first in the list. An empty list means the passthrough was spelled differently, or the key belongs to another app: each app sees only its own videos.

Next

On this page