Created by potrace 1.16, written by Peter Selinger 2001-2019

Miva Developer Docs


Adds an image to the store. Point it at an image file that’s already on the server, or send the image as base64 data and it creates the file for you. To attach an image to a product, use ProductImage_Add.

Before you begin#

  • Available in Miva 26.03.00 and later. Earlier versions return invalid_function.
  • The API token needs Image_Add, either assigned directly under Functions or through a group. See Create an API token.
  • Requests must be signed if the token requires it. See Make a signed request with HMAC.

Note

The file must first exist on the server at the path specified before calling this function, unless a base64 encoded image is supplied via the optional Image_Data parameter. Use FTP to upload the file to the server or the Miva admin.

Example requests#

Add an image that’s on the server#

Adds the image file already uploaded to graphics/00000001/logo-min.png.

{
    "Store_Code": "{{Store_Code}}",
    "Miva_Request_Timestamp": "{{$timestamp}}",
    "Function": "Image_Add",
    "Filepath": "graphics/00000001/logo-min.png"
}

Add a base64 encoded image#

Creates the image file at Filepath from the base64 data in Image_Data.

{
    "Store_Code": "{{Store_Code}}",
    "Miva_Request_Timestamp": "{{$timestamp}}",
    "Function": "Image_Add",
    "Filepath": "graphics/00000001/NEW.jpg",
    "Image_Data": "ADD_BASE64_IMAGE_HERE"
}

Request parameters#

Parameter Type Description
Filepath String Relative file path to the image (relative to mm5 folder). The file must already exist on the server, unless Image_Data is provided.
Image_Data String Optional. A base64 encoded image. When provided, the image file will be created from this data at the specified Filepath.

Example response#

{
    "success": 1,
    "data": {
        "id": 16,
        "image": "graphics/00000001/image/mivalearn_logo.png",
        "width": 420,
        "height": 420,
        "alt_text": "",
        "refcount": 0,
        "image_size": 10228,
        "image_mtime": 1784651010
    }
}

Response parameters#

Parameter Type Description
success Boolean Boolean value for if the request was successful
data Object The image that was added
data.id Number Image ID
data.image String File path of the image, relative to the mm5 folder
data.width Number Image width in pixels
data.height Number Image height in pixels
data.alt_text String Alt text for the image
data.refcount Number Number of places that use the image, such as products
data.image_size Number File size in bytes
data.image_mtime Number When the file was last modified, as a Unix timestamp

Error responses#

Error Code Error Message Error Description
MER-JSN-IMG-00009 Invalid image extension The file extension of the provided Filepath is not valid.
MER-DBE-IMG-00001 Image filepaths must be local and relative to the Base Directory for Graphics Filepath is not a local relative path.
Function Use it to
ProductImage_Add Add an image to a product
ProductImage_Delete Remove an image from a product
ProductImage_Update_Type Change the image type of a product image
ImageTypeList_Load_Query List the store’s image types

Try in Postman#

This function isn’t in the Miva Postman collection yet. See Set Up Postman to send it with your own request.