This method is used to add a new product image or replace an existing one on an existing product. A single product can be updated through each call. Each product can have up to four product images. This Web API method requires a multipart/form-data post, as defined in RFC 1867. There are many libraries available that can be used in order to submit multipart/form-data posts (for example MultipartEntity in Java)
Resource URL
Parameters
Name | Type | Description |
token | String | The token retrieved from the login method |
product_identifier (mandatory) | Identifier | The identifier of the product. The allowed product identifier fields are the following: Name | Type | Description |
---|
id (semi-optional) | String | The ID of the product | code (semi-optional) | String | The code of the product | alternative_code (semi-optional) | String | The alternative code of the product |
|
image_placeholder_order (mandatory) | String | The product image placing order The supported values are "image 1", "image 2", "image 3" and "image 4" |
alternative_text (mandatory) | String | The alternative text of the product image |
file (mandatory) | File | The file that should be added as a product image |
default (optional on conditions) | Boolean | Defines if the product image is set as the default This parameter is optional if the provided image is not the first image to be added to the product |
fields_set (optional) | List of Strings, comma separated | A list of fields that should be included in the results. If not specified then all the available fields will be returned |
Restrictions
- It is mandatory to specify one of the semi-optional parameters. Only one of those parameters is allowed to be specified.
Response Data
Name | Type | Description |
---|
images_set | Images Object | The product images |
Referred Objects Response Data
product_images object response data
Name | Type | Description |
---|
id | String | The ID of the retrieved product image |
image_placeholder_order | String | The product image placing order The supported values are "image 1", "image 2", "image 3" and "image 4" |
alternative_text | String | The alternative text of the product image |
default | Boolean | Defines if the product image is set as the default |
file | File Object | The information of the attached file |
Referred Objects Response Data
file object response data
Name | Type | Description |
---|
file_name | String | The name of the file |
file_content_url | String | The url that can be used to access the actual content of the file |
file_mime_type | String | The mime type of the attached file |
Examples
Example 1
HTTP Method: POST
PHP Example:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "8080",
CURLOPT_URL => "http://cyn1lnx028:8080/crmapi/rest/v2/products/images/add",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\neyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c3IiOiJNUEFkbWluaXN0cmF0b3IiLCJvcmciOiJwc19kZXYiLCJvdW4iOiIxIiwiZXhwIjoiMTUwMzkyMzIzMiIsImlhdCI6IjE1MDM5MTYwMzIiLCJqdGkiOiI2QzQ3OEIxN0ZEMzU0OUQ4QkU1RTU2OUFGMzVGOUQxQSJ9.V1h3-ln9zRKIBq3F0r_AyJg5W1zV6T5yU4Tmu9I1n2w\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"product_identifier\"\r\n\r\ncode=UPA16\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"image_placeholder_order\"\r\n\r\nimage 1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"alternative_text\"\r\n\r\ncamera\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"default\"\r\n\r\n1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"Cube.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
"cookie: JSESSIONID=9EDF628991051517EF72EDEE1E5396E6",
"postman-token: 1a276987-e0bb-60d4-a722-a76732da837d",
"x-atlassian-token: no-check"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}