Skip to content

GraphQL ​

The Mux plugin supports accessing muxAsset element object via GraphQL. Be sure to read about Craft's GraphQL support.

Available Queries ​

1. muxAssets ​

Query for multiple Mux assets with filtering and pagination options.

Type: [MuxAssetInterface] (Array of Mux Asset objects)

2. muxAsset ​

Query for a single Mux asset.

Type: MuxAssetInterface (Single Mux Asset object)

3. muxAssetCount ​

Get the count of Mux assets matching the query criteria.

Type: Int! (Non-null integer)

Query Parameters ​

Core Mux Asset Parameters ​

ParameterTypeDescription
id[QueryArgument]Narrows the query results based on the mux asset's ID
asset_id[QueryArgument]Narrows the query results based on the mux asset's asset_id
asset_status[String]Narrows the query results based on the mux asset's status
aspect_ratio[String]Narrows the query results based on the mux asset's aspect ratio
duration[QueryArgument]Narrows the query results based on the mux asset's duration
is_live[Boolean]Narrows the query results based on whether the asset is live
upload_id[QueryArgument]Narrows the query results based on the upload ID
playback_ids[QueryArgument]Narrows the query results based on playback IDs
tracks[QueryArgument]Narrows the query results based on tracks
passthrough[QueryArgument]Narrows the query results based on passthrough data
meta[QueryArgument]Narrows the query results based on meta data
folderId[QueryArgument]Narrows the query results based on the folder ID
volumeId[QueryArgument]Narrows the query results based on the volume ID

Inherited Element Parameters ​

ParameterTypeDescription
uid[String]Narrows the query results based on the elements' UIDs
site[String]Determines which site(s) the elements should be queried in
uniqueBooleanDetermines whether only elements with unique IDs should be returned
preferSites[QueryArgument]Determines which site should be selected for multi-site elements
title[String]Narrows the query results based on the elements' titles
slug[String]Narrows the query results based on the elements' slugs
uri[String]Narrows the query results based on the elements' URIs
searchStringNarrows the query results to elements that match a search query
searchTermOptionsSearchTermOptionsDefines default options for search terms
relatedTo[QueryArgument]Narrows results to elements that relate to provided element IDs
notRelatedTo[QueryArgument]Narrows results to elements that do not relate to provided element IDs
relatedToAssets[AssetRelation]Narrows results to elements that relate to an asset list
relatedToEntries[EntryRelation]Narrows results to elements that relate to an entry list
relatedToUsers[UserRelation]Narrows results to elements that relate to a user list
relatedToCategories[CategoryRelation]Narrows results to elements that relate to a category list
relatedToTags[TagRelation]Narrows results to elements that relate to a tag list
relatedToAll[QueryArgument]Narrows results to elements that relate to ALL provided element IDs
ref[String]Narrows the query results based on a reference string
fixedOrderBooleanCauses results to be returned in the order specified by the id argument
inReverseBooleanCauses results to be returned in reverse order
dateCreated[String]Narrows results based on the elements' creation dates
dateUpdated[String]Narrows results based on the elements' last-updated dates
offsetIntSets the offset for paginated results
language[String]Determines which site(s) to query based on language
limitIntSets the limit for paginated results
orderByStringSets the field the returned elements should be ordered by
siteSettingsId[QueryArgument]Narrows results based on unique identifier for element-site relation

Status Parameters (if permissions allow) ​

ParameterTypeDescription
status[String]Narrows results based on the elements' statuses
archivedBooleanNarrows results to only archived elements
trashedBooleanNarrows results to only soft-deleted elements

Draft Parameters (if permissions allow) ​

ParameterTypeDescription
draftsBooleanWhether draft elements should be returned
draftOfQueryArgumentNarrows results to only drafts of a given element
draftIdIntThe ID of the draft to return
draftCreatorIntThe drafts' creator ID
provisionalDraftsBooleanWhether provisional drafts should be returned
withProvisionalDraftsBooleanWhether canonical elements should be replaced with provisional drafts

Revision Parameters (if permissions allow) ​

ParameterTypeDescription
revisionsBooleanWhether revision elements should be returned
revisionOfQueryArgumentThe source element ID that revisions should be returned for
revisionIdIntThe ID of the revision to return
revisionCreatorIntThe revisions' creator ID

Response Structure ​

MuxAssetInterface Fields ​

FieldTypeDescription
idIDElement ID
asset_idStringID of the mux asset
volumeIdIDVolume ID
folderIdIDFolder ID
created_atStringCreation time of the object
asset_statusStringStatus of the mux asset
durationStringDuration of the object
max_stored_resolutionStringMax stored resolution of the object
max_stored_frame_rateStringMax stored frame rate of the object
resolution_tierStringResolution tier of the object
max_resolution_tierStringMax resolution tier of the object
encoding_tierStringEncoding tier of the object
aspect_ratioStringAspect ratio of the object
isAudioOnlyBooleanWhether the asset has tracks but no video track
playback_ids(policy)[PlaybackID]Playback IDs of the object. Optional policy: "public" or "signed" returns only that kind. Each one can return tokens and URLs; see PlaybackID Type.
tracks[Track]Tracks of the object
errorsStringErrors of the object
per_title_encodeStringPer-title encode of the object
upload_idStringUpload ID of the object
is_liveStringIndicates whether the object is live or not
passthroughStringPassthrough of the object
live_stream_idStringLive stream ID of the object
masterStringMaster of the object
master_accessStringMaster access
mp4_supportStringMP4 support (depreciated)
source_asset_idStringSource Asset Id
nomralize_audioStringNormalize Audio
static_renditionsStringStatic Renditions
recording_timesStringRecording Times
non_standard_input_reasonsStringNon Standard Input Reasons
testStringTest flag
ingest_typeStringIngest type
metaMetaMeta data of the object

PlaybackID Type ​

FieldTypeDescription
idStringThe playback ID
policyStringpublic or signed
token(type, …)StringToken (JWT) for a signed playback ID. null for public IDs. 2.8.0
streamUrl(…)Stringhttps://stream.mux.com/{id}.m3u8 2.8.0
thumbnailUrl(format, …)Stringhttps://image.mux.com/{id}/thumbnail.{format} 2.8.0
animatedUrl(format, …)Stringhttps://image.mux.com/{id}/animated.{format} 2.8.0
storyboardUrl(format)Stringhttps://image.mux.com/{id}/storyboard.{format} 2.8.0
textTrackUrl(trackId)Stringhttps://stream.mux.com/{id}/text/{trackId}.vtt 2.8.0
staticRenditionUrl(name, download)Stringhttps://stream.mux.com/{id}/{name} (MP4/M4A) 2.8.0

The URL fields add ?token=… for signed playback IDs and put modifiers in the query string for public ones, so the URL is ready to use either way. Signed tokens and URLs require the schema permission.

Arguments every token and URL field accepts ​

ArgumentTypeDescription
expiresInIntMinimum lifetime in seconds. Default signedTokenLifetime (24 hours), capped at maxSignedTokenLifetime (365 days). Ignored for public IDs.
playback_restriction_idStringMux playback restriction to enforce. Default: the Default Playback Restriction ID setting. Pass "" to leave it out. Ignored for public IDs.

token arguments ​

ArgumentTypeDefaultDescription
typeString"v"v/video (stream, captions, downloads), t/thumbnail, g/gif, s/storyboard. Anything else returns an Invalid token type error.
modifiersAny modifier from the tables below. Only the ones that belong to type are put in the token; the rest are ignored.

streamUrl modifiers (token type v) ​

ArgumentTypeDescription
max_resolutionStringHighest rendition, e.g. 720p
min_resolutionStringLowest rendition, e.g. 480p
rendition_orderStringdesc
redundant_streamsBooleanInclude redundant streams
roku_trick_playBooleanRoku timeline previews
default_subtitles_langStringBCP47 code of the default subtitles track
asset_start_time, asset_end_timeFloatInstant clipping, seconds
program_start_time, program_end_timeIntInstant clipping, epoch timestamps

thumbnailUrl modifiers (token type t) ​

ArgumentTypeDescription
formatStringwebp (default), jpg, png
timeFloatSeconds into the video
width, heightIntPixels
fit_modeStringpreserve, stretch, crop, smartcrop, pad
rotateInt90, 180, 270
flip_v, flip_hBooleanFlip vertically / horizontally

animatedUrl modifiers (token type g) ​

ArgumentTypeDescription
formatStringgif (default), webp
start, endFloatSeconds. Max 10 seconds long.
width, heightIntPixels, max 640
fpsIntFrame rate, max 30

Other URL fields ​

FieldArguments
storyboardUrlformat: vtt (default), json, jpg, png, webp
textTrackUrltrackId (required): ID of a text track from tracks
staticRenditionUrlname (required): e.g. highest.mp4, 1080p.mp4, audio.m4a. download: file name to save as.

Track Type ​

FieldTypeDescription
idStringTrack ID
typeStringTrack type
text_sourceStringText source
text_typeStringText type
language_codeStringLanguage code
nameStringTrack name
closed_captionsStringClosed captions
durationFloatThe duration of the track in seconds
max_widthIntThe maximum width of the track
max_heightIntThe maximum height of the track
max_frame_rateIntThe maximum frame rate of the track

Meta Type ​

FieldTypeDescription
titleStringTitle of the asset
external_idStringExternal ID of the asset
creator_idStringCreator ID of the asset

Example Queries ​

Basic Query - Get All Mux Assets ​

graphql
query {
  muxAssets {
    id
    asset_id
    asset_status
    duration
    aspect_ratio
    isAudioOnly
    created_at
    playback_ids {
      id
      policy
    }
    tracks {
      id
      type
      duration
      max_width
      max_height
      language_code
    }
    meta {
      title
      external_id
      creator_id
    }
  }
}
json
{
  "data": {
    "muxAssets": [
      {
        "id": "123",
        "asset_id": "abc123def456",
        "asset_status": "ready",
        "duration": "120.5",
        "aspect_ratio": "16:9",
        "isAudioOnly": false,
        "created_at": "2023-12-01T10:30:00Z",
        "playback_ids": [
          {
            "id": "playback_123",
            "policy": "public"
          }
        ],
        "tracks": [
          {
            "id": "track_123",
            "type": "video",
            "duration": 120.5,
            "max_width": 1920,
            "max_height": 1080,
            "max_frame_rate": 30,
            "language_code": "en"
          },
          {
            "id": "track_124",
            "type": "audio",
            "duration": 120.5,
            "language_code": "en"
          }
        ],
        "meta": {
          "title": "Sample Video",
          "external_id": "ext_123",
          "creator_id": "user_456"
        }
      }
    ]
  }
}

Filtered Query - Get Live Assets with Specific Status ​

graphql
query {
  muxAssets(
    asset_status: ["ready"]
    is_live: [true]
    limit: 10
    orderBy: "created_at"
  ) {
    id
    asset_id
    asset_status
    is_live
    duration
    aspect_ratio
    playback_ids {
      id
      policy
    }
    tracks {
      id
      type
      duration
      max_width
      max_height
    }
    meta {
      title
      external_id
    }
  }
}

Single Asset Query ​

graphql
query {
  muxAsset(asset_id: ["your-asset-id-here"]) {
    id
    asset_id
    asset_status
    duration
    aspect_ratio
    isAudioOnly
    max_stored_resolution
    max_stored_frame_rate
    resolution_tier
    encoding_tier
    playback_ids {
      id
      policy
    }
    tracks {
      id
      type
      text_type
      language_code
      name
      duration
      max_width
      max_height
      max_frame_rate
    }
    meta {
      title
      external_id
      creator_id
    }
    errors
    upload_id
    passthrough
    live_stream_id
    master
    master_access
    mp4_support
    source_asset_id
    static_renditions
    recording_times
    non_standard_input_reasons
    test
    ingest_type
  }
}
json
{
  "data": {
    "muxAsset": {
      "id": "123",
      "asset_id": "abc123def456ghi789",
      "asset_status": "ready",
      "duration": "120.5",
      "aspect_ratio": "16:9",
      "isAudioOnly": false,
      "max_stored_resolution": "1920x1080",
      "max_stored_frame_rate": "30",
      "resolution_tier": "1080p",
      "encoding_tier": "smart",
      "playback_ids": [
        {
          "id": "playback_123456789",
          "policy": "public"
        },
        {
          "id": "playback_987654321",
          "policy": "signed"
        }
      ],
      "tracks": [
        {
          "id": "track_video_123",
          "type": "video",
          "text_type": null,
          "language_code": "en",
          "name": "Main Video Track",
          "duration": 120.5,
          "max_width": 1920,
          "max_height": 1080,
          "max_frame_rate": 30
        },
        {
          "id": "track_audio_124",
          "type": "audio",
          "text_type": null,
          "language_code": "en",
          "name": "Stereo Audio",
          "duration": 120.5,
          "max_width": null,
          "max_height": null,
          "max_frame_rate": null
        },
        {
          "id": "track_subtitles_125",
          "type": "text",
          "text_type": "subtitles",
          "language_code": "en",
          "name": "English Subtitles",
          "duration": 120.5,
          "max_width": null,
          "max_height": null,
          "max_frame_rate": null
        }
      ],
      "meta": {
        "title": "Sample Marketing Video",
        "external_id": "marketing_video_001",
        "creator_id": "user_456789"
      },
      "errors": null,
      "upload_id": "upload_abc123def456",
      "passthrough": "{\"project\":\"marketing\",\"campaign\":\"q4_2023\"}",
      "live_stream_id": null,
      "master": "{\"access\":\"public\",\"url\":\"https://stream.mux.com/abc123def456.m3u8\"}",
      "master_access": "public",
      "mp4_support": "standard",
      "source_asset_id": null,
      "static_renditions": "{\"files\":[{\"name\":\"track_video_123.mp4\",\"ext\":\"mp4\",\"height\":720,\"width\":1280}]}",
      "recording_times": null,
      "non_standard_input_reasons": null,
      "test": false,
      "ingest_type": "on_demand"
    }
  }
}

Signed Playback 2.8.0 ​

Signed playback IDs need a token on every URL. The plugin can create the tokens, or complete URLs, directly in your GraphQL response. Signed Playback explains tokens, lifetimes and restrictions in detail.

Signed playback permission ​

Tokens and signed URLs are only returned to schemas with the Mux → Generate signed playback tokens and URLs permission (muxSignedPlayback:read). Enable it in GraphQL → Schemas.

Schema has the permissionSigned playback IDPublic playback ID
Yestoken and URL fields filled intoken is null, URL fields filled in
Notoken and URL fields are nulltoken is null, URL fields filled in

Only enable it on private schemas

Anyone using the schema can create tokens for every signed video it can query. Never enable it on the public schema, and keep the schema's access token on your server. The CP's GraphiQL Full Schema includes the permission, which is handy for testing.

Query the playback IDs once and decide from policy. This works for every asset, public or signed.

graphql
query Videos {
  muxAssets(limit: 10) {
    id
    title
    ... on MuxAssetInterface {
      playback_ids {
        id
        policy
        playbackToken: token(type: "v")
        thumbnailToken: token(type: "t", time: 2)
        storyboardToken: token(type: "s")
      }
    }
  }
}
json
{
  "data": {
    "muxAssets": [
      {
        "id": "101",
        "title": "Signed Video",
        "playback_ids": [
          {
            "id": "a1B2c3D4e5F6g7H8i9J0kLmNoPqRsTuVwXyZ",
            "policy": "signed",
            "playbackToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs…",
            "thumbnailToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs…",
            "storyboardToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs…"
          }
        ]
      },
      {
        "id": "102",
        "title": "Public Clip",
        "playback_ids": [
          {
            "id": "Zy9Xw8Vu7Ts6Rq5Po4Nm3Lk2Ji1Hg0Fe",
            "policy": "public",
            "playbackToken": null,
            "thumbnailToken": null,
            "storyboardToken": null
          }
        ]
      }
    ]
  }
}
html
<!-- Signed: pass all three tokens. Public: leave them out. -->
<mux-player
  playback-id="a1B2c3D4e5F6g7H8i9J0kLmNoPqRsTuVwXyZ"
  playback-token="eyJ…"
  thumbnail-token="eyJ…"
  storyboard-token="eyJ…">
</mux-player>

A null token doesn't mean "public"

token is also null for a signed ID when the schema lacks the permission, no signing key exists, or signing failed. Decide from policy:

js
const pb = asset.playback_ids[0];
if (pb.policy === 'signed' && !pb.playbackToken) {
  // Misconfigured: don't render a player that will get a 403.
}

Ready-made URLs ​

For <img> tags, downloads, captions or a custom player, ask for URLs instead of tokens. They work the same for public and signed IDs.

graphql
query VideoUrls {
  muxAsset(id: 101) {
    ... on MuxAssetInterface {
      tracks { id type name language_code }
      playback_ids {
        policy
        streamUrl(max_resolution: "720p")
        poster: thumbnailUrl(width: 1280, time: 2, format: "jpg")
        card: thumbnailUrl(width: 400, height: 400, fit_mode: "smartcrop")
        preview: animatedUrl(width: 320, start: 0, end: 4)
        storyboardUrl
        download: staticRenditionUrl(name: "highest.mp4", download: "my-video.mp4")
      }
    }
  }
}

Caption URLs need a track ID, so get tracks first, then:

graphql
query Captions {
  muxAsset(id: 101) {
    ... on MuxAssetInterface {
      playback_ids {
        textTrackUrl(trackId: "YOUR_TEXT_TRACK_ID")
      }
    }
  }
}

Token lifetime ​

graphql
playback_ids {
  day: token                                # default: at least 24 hours
  hour: token(expiresIn: 3600)              # at least 1 hour
  year: token(expiresIn: 31536000)          # at least 365 days (the default maximum)
}

Craft's GraphQL response cache expires automatically before cached tokens do. If you cache responses yourself (SSR render cache, CDN, static build), keep that cache shorter than the token lifetime. See Caching pages that contain tokens.

Playback restrictions ​

graphql
playback_ids {
  default: token                                             # uses the Default Playback Restriction ID setting, if set
  restricted: token(playback_restriction_id: "YOUR_RESTRICTION_ID")    # this restriction
  unrestricted: token(playback_restriction_id: "")           # no restriction, even if a default is set
}

Every token and URL field accepts playback_restriction_id, including storyboardUrl, textTrackUrl and staticRenditionUrl. Restrictions only apply to signed playback IDs; public IDs ignore the argument. See Playback Restrictions for setup, variables and troubleshooting.

Assets with public and signed playback IDs ​

An asset can have both kinds of playback ID (see An asset can have both). To get a specific kind, filter with policy and give each list an alias:

graphql
query ByPolicy($ids: [QueryArgument]) {
  muxAssets(id: $ids) {
    id
    ... on MuxAssetInterface {
      signedPlaybackIds: playback_ids(policy: "signed") {
        id
        playbackToken: token(type: "v")
      }
      publicPlaybackIds: playback_ids(policy: "public") {
        id
      }
    }
  }
}
One list, branch on policySplit by policy
Best forProduction frontendsAssets with both kinds of ID, testing
Response shapeSame for every assetTwo lists; one may be empty []
Asset with only the other kindStill returnedEmpty list: handle it

Use every variable you declare

GraphQL rejects a query that declares a variable it doesn't use, e.g. Variable "$restriction" is never used in operation "ByPolicy". Remove unused variables, or pass them to a field such as token(playback_restriction_id: $restriction).

Testing in GraphiQL ​

Open GraphQL → GraphiQL in the CP, choose Full Schema, and run:

graphql
query SecureVideoTest($ids: [QueryArgument]) {
  muxAssets(id: $ids) {
    id
    title
    ... on MuxAssetInterface {
      playback_ids {
        id
        policy
        playbackToken: token(type: "v")
        streamUrl
        thumbnailUrl(width: 640, format: "jpg")
        storyboardUrl
      }
    }
  }
}
json
{ "ids": [101, 102] }
  • Open thumbnailUrl and storyboardUrl in a browser. They should load.
  • Safari plays streamUrl directly. In other browsers, test with <mux-player> and the playbackToken.
  • Paste a token into jwt.io to see its contents: sub (playback ID), aud (token type), exp (expiry) and any modifiers.
  • Run the same query with a schema without the permission: signed playbackToken and URLs become null.

Notes ​

  • All queries require appropriate GraphQL permissions to be configured in Craft CMS
  • The QueryArgument type supports various comparison operators (equals, not equals, greater than, less than, etc.)
  • Date parameters accept various formats including ISO 8601 strings
  • The search parameter performs full-text search across searchable fields
  • Pagination is handled through limit and offset parameters
  • Results can be ordered using the orderBy parameter with field names