Add a Product Media item

POST /api/v2/products/{productId}/media.json

Add a Media item to a Product.

Scope

Requires the products OAuth scope.

Path parameters

productId required
The ID of the Product is supplied as a path parameter.


Request body

Your request body must contain an object including:

data required
Containing a Product Media object.


Example

To add a Product Media item you must POST JSON to this resource within a data object. The minimum requirement for a media item is an image value. In the example below we're supplying an image using a Data URI

{
    "data": {
        "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..."
    }
}

Importing media using a Data URI will result in a new filename based on the md5 of the file contents and it's location in the Media Library will be based on the file's mime type. However, this may not be desirable if you wish to maintain searchable filenames. You can define your preferred filename and/or directory for your Data URI using a Content URI request object, which consists of a src, filename and directory property (as illustrated below).

{
    "data": {
        "image": {
            "src": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...",
            "filename": "my-image-name.png",
            "directory": "˜/content/images/products"
        }
    }
}

Note that the directory, if supplied, must be a valid Content URI starting with ~/content. If the directory is not supplied it will be calculated based on the file's mime type.

Success responses

If the Product Media was created successfully you should receive a response with a 201 status code:

success
A boolean where a value of true means the Media was created successfully.
status
The HTTP status code e.g. 201 means the Media was created successfully.
data
Contains the Product Media object you created including its new id and any URLs to imported image, video or frames.


Error responses

If the Media item could not be created you will encounter a response with a 422 status code:

success
A boolean where a value of false means the Media item could not be created.
status
A response code of 422 means the Media item could not be created and you should check the errors property for further information.
context
The context property indicates where the error occurred. For a 422 error this will typically contain a value of data, indicating that there was an error with the data object supplied.
errors

Contains an array of error objects, each will have the following properties:

  • name - The property name that encountered an error.
  • message - A human readable error message.
  • ref - An error reference string (e.g. error.not-unique if the alias supplied is already in use).