Skip to content

Powered by Grav CMS + Helios Theme

Product media

Pictures, video, embeds and samples attached to a product.

Pictures, video, embeds and samples attached to a product. GET /kahunacart/products/{id}/images is the older read that answers gallery pictures only, kept for clients written before media existed. The image object and its url field are on Products and catalog.

List product media

GET /api/v1/kahunacart/products/{id}/media Permission kahunacart.products.manage

Everything attached to a product, gallery first and then the samples. Each row carries its kind (image, video, audio, document or embed), its role (gallery, sample, or label for the files a product label is made of), the stored path and site-relative url, or the embed url for a third-party player, plus mime, bytes, duration in seconds, alt text, position and the resolved poster image. Narrow with role or kind. Uploading bytes is not available through this interface; an embed is, because it has none.

Parameters

Name Type Description
id required integer Product id
role optional string
One of: gallery, sample, label
kind optional string
One of: image, video, audio, document, embed

List product images

GET /api/v1/kahunacart/products/{id}/images Permission kahunacart.products.manage

The compatibility view of the above: a product's gallery pictures alone, each as id, stored path, site-relative url, alt text and position. This is what a client written before product media existed means by "images", and it never returns a clip, a sample or an embed.

Parameters

Name Type Description
id required integer Product id

Add a video embed to a product

POST /api/v1/kahunacart/products/{id}/media/embeds Permission kahunacart.products.manage

Attach a third-party video by URL. No bytes are uploaded: the row holds the canonical embed URL, and the storefront draws a click-to-load placeholder that fetches nothing from the video host until a shopper presses play. The host has to be on the store's media.embed_hosts allowlist (YouTube, YouTube nocookie and Vimeo by default) and the URL has to be https, or the call is refused with a 422. A watch, share or shorts URL is accepted and stored in its embed form. A poster has to be a gallery image of the same product.

Parameters

Name Type Description
id required integer Product id
embed_url required string https URL on an allowlisted host
alt optional string or null What the video shows
role optional string
One of: gallery, sample
Default: gallery
poster_media_id optional integer or null A gallery image of this product to show before the video loads

Update a piece of product media

PATCH /api/v1/kahunacart/products/{id}/media/{mediaId} Permission kahunacart.products.manage

Change a row's alt text, its place in its list, its recorded duration, its poster, or an embed's URL. The bytes are immutable, so replacing a file means uploading a new one and deleting the old. An empty alt string declares a picture decorative. The role is not editable: moving a video from the gallery to the samples means deleting it and adding it where you want it.

Parameters

Name Type Description
id required integer Product id
mediaId required integer Product media id
alt optional string or null 255 characters or fewer.
position optional integer At least 0.
duration_seconds optional integer or null Length of an audio or video row, where it is known
poster_media_id optional integer or null A gallery image of this product, or null to clear it
embed_url optional string Only on an embed row, and only an allowlisted https host

Reorder a product's gallery or samples

POST /api/v1/kahunacart/products/{id}/media/reorder Permission kahunacart.products.manage

Put a product's gallery, or its samples, in the order of the ids given, in one transaction. The first gallery image is the product's main picture, so naming an image first makes it the main one. Rows of that list left out keep their order after the ones named. Every id must be a row of this product in that role, or nothing is changed.

Parameters

Name Type Description
id required integer Product id
role optional string Which list to reorder; gallery when left out
One of: gallery, sample
ids required array of integer Product media ids in their new order

Delete a piece of product media

DELETE /api/v1/kahunacart/products/{id}/media/{mediaId} Permission kahunacart.products.manage

Detach a row from its product and delete the bytes on disk, where there are any. Every option value, variant and poster pointing at it is cleared at the same time.

Parameters

Name Type Description
id required integer Product id
mediaId required integer Product media id

Upload product media

POST /api/v1/kahunacart/products/{id}/media Permission kahunacart.products.manage

Upload a picture, video, audio file or PDF for a product. multipart/form-data; the kind is decided by reading the bytes, and the ceiling is images.max_upload_mb or media.max_upload_mb.

The format is decided by reading the bytes, not the extension. Anything that is not JPEG, PNG, WebP, AVIF or GIF is a 415, and a file over images.max_upload_mb (8 by default) is a 413.