Add a Product Download

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

Add a Download 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 Download object.


Example

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

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

Importing downloads 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": {
        "file": {
            "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 Download was created successfully you should receive a response with a 201 status code:

success
A boolean where a value of true means the object was created successfully.
status
The HTTP status code e.g. 201 means the object was created successfully.
data
Contains the Product Download object you created including its new id.


Error responses

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

success
A boolean where a value of false means the object could not be created.
status
A response code of 422 means theobject 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).