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
| Parameter | Type | Description |
|---|---|---|
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
| Parameter | Type | Description |
|---|---|---|
uid | [String] | Narrows the query results based on the elements' UIDs |
site | [String] | Determines which site(s) the elements should be queried in |
unique | Boolean | Determines 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 |
search | String | Narrows the query results to elements that match a search query |
searchTermOptions | SearchTermOptions | Defines 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 |
fixedOrder | Boolean | Causes results to be returned in the order specified by the id argument |
inReverse | Boolean | Causes 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 |
offset | Int | Sets the offset for paginated results |
language | [String] | Determines which site(s) to query based on language |
limit | Int | Sets the limit for paginated results |
orderBy | String | Sets 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)
| Parameter | Type | Description |
|---|---|---|
status | [String] | Narrows results based on the elements' statuses |
archived | Boolean | Narrows results to only archived elements |
trashed | Boolean | Narrows results to only soft-deleted elements |
Draft Parameters (if permissions allow)
| Parameter | Type | Description |
|---|---|---|
drafts | Boolean | Whether draft elements should be returned |
draftOf | QueryArgument | Narrows results to only drafts of a given element |
draftId | Int | The ID of the draft to return |
draftCreator | Int | The drafts' creator ID |
provisionalDrafts | Boolean | Whether provisional drafts should be returned |
withProvisionalDrafts | Boolean | Whether canonical elements should be replaced with provisional drafts |
Revision Parameters (if permissions allow)
| Parameter | Type | Description |
|---|---|---|
revisions | Boolean | Whether revision elements should be returned |
revisionOf | QueryArgument | The source element ID that revisions should be returned for |
revisionId | Int | The ID of the revision to return |
revisionCreator | Int | The revisions' creator ID |
Response Structure
MuxAssetInterface Fields
| Field | Type | Description |
|---|---|---|
id | ID | Element ID |
asset_id | String | ID of the mux asset |
volumeId | ID | Volume ID |
folderId | ID | Folder ID |
created_at | String | Creation time of the object |
asset_status | String | Status of the mux asset |
duration | String | Duration of the object |
max_stored_resolution | String | Max stored resolution of the object |
max_stored_frame_rate | String | Max stored frame rate of the object |
resolution_tier | String | Resolution tier of the object |
max_resolution_tier | String | Max resolution tier of the object |
encoding_tier | String | Encoding tier of the object |
aspect_ratio | String | Aspect ratio of the object |
isAudioOnly | Boolean | Whether 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 |
errors | String | Errors of the object |
per_title_encode | String | Per-title encode of the object |
upload_id | String | Upload ID of the object |
is_live | String | Indicates whether the object is live or not |
passthrough | String | Passthrough of the object |
live_stream_id | String | Live stream ID of the object |
master | String | Master of the object |
master_access | String | Master access |
mp4_support | String | MP4 support (depreciated) |
source_asset_id | String | Source Asset Id |
nomralize_audio | String | Normalize Audio |
static_renditions | String | Static Renditions |
recording_times | String | Recording Times |
non_standard_input_reasons | String | Non Standard Input Reasons |
test | String | Test flag |
ingest_type | String | Ingest type |
meta | Meta | Meta data of the object |
PlaybackID Type
| Field | Type | Description |
|---|---|---|
id | String | The playback ID |
policy | String | public or signed |
token(type, …) | String | Token (JWT) for a signed playback ID. null for public IDs. 2.8.0 |
streamUrl(…) | String | https://stream.mux.com/{id}.m3u8 2.8.0 |
thumbnailUrl(format, …) | String | https://image.mux.com/{id}/thumbnail.{format} 2.8.0 |
animatedUrl(format, …) | String | https://image.mux.com/{id}/animated.{format} 2.8.0 |
storyboardUrl(format) | String | https://image.mux.com/{id}/storyboard.{format} 2.8.0 |
textTrackUrl(trackId) | String | https://stream.mux.com/{id}/text/{trackId}.vtt 2.8.0 |
staticRenditionUrl(name, download) | String | https://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
| Argument | Type | Description |
|---|---|---|
expiresIn | Int | Minimum lifetime in seconds. Default signedTokenLifetime (24 hours), capped at maxSignedTokenLifetime (365 days). Ignored for public IDs. |
playback_restriction_id | String | Mux playback restriction to enforce. Default: the Default Playback Restriction ID setting. Pass "" to leave it out. Ignored for public IDs. |
token arguments
| Argument | Type | Default | Description |
|---|---|---|---|
type | String | "v" | v/video (stream, captions, downloads), t/thumbnail, g/gif, s/storyboard. Anything else returns an Invalid token type error. |
| modifiers | Any 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)
| Argument | Type | Description |
|---|---|---|
max_resolution | String | Highest rendition, e.g. 720p |
min_resolution | String | Lowest rendition, e.g. 480p |
rendition_order | String | desc |
redundant_streams | Boolean | Include redundant streams |
roku_trick_play | Boolean | Roku timeline previews |
default_subtitles_lang | String | BCP47 code of the default subtitles track |
asset_start_time, asset_end_time | Float | Instant clipping, seconds |
program_start_time, program_end_time | Int | Instant clipping, epoch timestamps |
thumbnailUrl modifiers (token type t)
| Argument | Type | Description |
|---|---|---|
format | String | webp (default), jpg, png |
time | Float | Seconds into the video |
width, height | Int | Pixels |
fit_mode | String | preserve, stretch, crop, smartcrop, pad |
rotate | Int | 90, 180, 270 |
flip_v, flip_h | Boolean | Flip vertically / horizontally |
animatedUrl modifiers (token type g)
| Argument | Type | Description |
|---|---|---|
format | String | gif (default), webp |
start, end | Float | Seconds. Max 10 seconds long. |
width, height | Int | Pixels, max 640 |
fps | Int | Frame rate, max 30 |
Other URL fields
| Field | Arguments |
|---|---|
storyboardUrl | format: vtt (default), json, jpg, png, webp |
textTrackUrl | trackId (required): ID of a text track from tracks |
staticRenditionUrl | name (required): e.g. highest.mp4, 1080p.mp4, audio.m4a. download: file name to save as. |
Track Type
| Field | Type | Description |
|---|---|---|
id | String | Track ID |
type | String | Track type |
text_source | String | Text source |
text_type | String | Text type |
language_code | String | Language code |
name | String | Track name |
closed_captions | String | Closed captions |
duration | Float | The duration of the track in seconds |
max_width | Int | The maximum width of the track |
max_height | Int | The maximum height of the track |
max_frame_rate | Int | The maximum frame rate of the track |
Meta Type
| Field | Type | Description |
|---|---|---|
title | String | Title of the asset |
external_id | String | External ID of the asset |
creator_id | String | Creator ID of the asset |
Example Queries
Basic Query - Get All Mux Assets
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
}
}
}{
"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
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
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
}
}{
"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 permission | Signed playback ID | Public playback ID |
|---|---|---|
| Yes | token and URL fields filled in | token is null, URL fields filled in |
| No | token and URL fields are null | token 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.
Tokens for <mux-player> (recommended)
Query the playback IDs once and decide from policy. This works for every asset, public or signed.
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")
}
}
}
}{
"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
}
]
}
]
}
}<!-- 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:
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.
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:
query Captions {
muxAsset(id: 101) {
... on MuxAssetInterface {
playback_ids {
textTrackUrl(trackId: "YOUR_TEXT_TRACK_ID")
}
}
}
}Token lifetime
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
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:
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 policy | Split by policy | |
|---|---|---|
| Best for | Production frontends | Assets with both kinds of ID, testing |
| Response shape | Same for every asset | Two lists; one may be empty [] |
| Asset with only the other kind | Still returned | Empty 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:
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
}
}
}
}{ "ids": [101, 102] }- Open
thumbnailUrlandstoryboardUrlin a browser. They should load. - Safari plays
streamUrldirectly. In other browsers, test with<mux-player>and theplaybackToken. - 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
playbackTokenand URLs becomenull.
Notes
- All queries require appropriate GraphQL permissions to be configured in Craft CMS
- The
QueryArgumenttype supports various comparison operators (equals, not equals, greater than, less than, etc.) - Date parameters accept various formats including ISO 8601 strings
- The
searchparameter performs full-text search across searchable fields - Pagination is handled through
limitandoffsetparameters - Results can be ordered using the
orderByparameter with field names