lib/api/productimage.js
import { get } from '../methods/get';
import { post } from '../methods/post';
import { remove } from '../methods/remove';
import { put } from '../methods/put';
/**
* GET /admin/products/{product_id}/images/{image_id}.json
*
* Examples:
*
* insales.getProductImage({
* token: '1234567890',
* url: 'shop-test.myinsales.ru',
* productid: '1',
* productimageid: '4355'
* }).then(response => {
* console.info(response.data);
* }).catch(err => {
* console.error(err);
* });
* Output:
*
* {
* "id": 4355,
* "product_id": 1,
* "external_id": null,
* "position": 1,
* "created_at": "2026-10-21T23:12:42.000+03:00",
* "image_processing": true,
* "title": null,
* "url": "/images/loading.gif",
* "original_url": "/images/loading.gif",
* "medium_url": "/images/loading.gif",
* "small_url": "/images/loading.gif",
* "thumb_url": "/images/loading.gif",
* "compact_url": "/images/loading.gif",
* "large_url": "/images/loading.gif",
* "filename": "image.jpg",
* "has_bitmap_image": false,
* "image_content_type": "image/jpeg"
* }
* @param {Object} options
* @param {string} options.token Required, access token for shop
* @param {string} options.url Required, shop url
* @param {number|string} options.productid Required, product id
* @param {number|string} options.productimageid Required, product image id
* @param {Number|String} id Required, app id
* @returns {Promise}
*/
export function getProductImage(options, id) {
return get({
id,
token: options.token,
url: options.url,
api: `products/${options.productid}/images/${options.productimageid}`
});
}
/**
* GET /admin/products/{product_id}/images.json
*
* Examples:
*
* insales.listProductImage({
* token: '1234567890',
* url: 'shop-test.myinsales.ru',
* productid: '1'
* }).then(response => {
* console.info(response.data);
* }).catch(err => {
* console.error(err);
* });
* Output:
*
* []
* @param {Object} options
* @param {string} options.token Required, access token for shop
* @param {string} options.url Required, shop url
* @param {number|string} options.productid Required, product id
* @param {Number|String} id Required, app id
* @returns {Promise}
*/
export function listProductImage(options, id) {
return get({
id,
token: options.token,
url: options.url,
api: `products/${options.productid}/images`
});
}
/**
* POST /admin/products/{product_id}/images.json
*
* Examples:
*
* insales.createProductImage({
* token: '1234567890',
* url: 'shop-test.myinsales.ru',
* productid: '1',
* productimage: {
* "image": {
* "src": "https://abc.myinsales.ru/images/no_image_compact.jpg"
* }
* }
* }).then(response => {
* console.info(response.data);
* }).catch(err => {
* console.error(err);
* });
* Output:
*
* {
* "id": 4371,
* "product_id": 1,
* "external_id": null,
* "position": 1,
* "created_at": "2026-10-21T23:12:43.000+03:00",
* "image_processing": true,
* "title": null,
* "url": "/images/loading.gif",
* "original_url": "/images/loading.gif",
* "medium_url": "/images/loading.gif",
* "small_url": "/images/loading.gif",
* "thumb_url": "/images/loading.gif",
* "compact_url": "/images/loading.gif",
* "large_url": "/images/loading.gif",
* "filename": "no_image_compact.jpg",
* "has_bitmap_image": false,
* "image_content_type": "image/jpeg"
* }
*
* insales.createProductImage({
* token: '1234567890',
* url: 'shop-test.myinsales.ru',
* productid: '1',
* productimage: {
* "image": {
* "attachment": "/9j/4AAQSkZJRgABAQEASABIAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4w\nICh1c2luZyBJSkcgSlBFRyB2NjIpLCBkZWZhdWx0IHF1YWxpdHkK/9sAQwAG\nBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxobIxwWFiAs\nICMmJykqKRkfLTAtKDAlKCko/9sAQwEHBwcKCAoTCgoTKBoWGigoKCgoKCgo\nKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo/8AA\nEQgAWQBkAwEiAAIRAQMRAf/EAB0AAAEEAwEBAAAAAAAAAAAAAAgABQYHAQME\nAgn/xABEEAABAwMBBAYHBgIHCQAAAAABAgMEAAURBgcSITEIE0FRYYEUIjJx\nkbHSIzd1lKGzFRg1QkNSYqLwJSYzY3KCksLT/8QAGQEAAgMBAAAAAAAAAAAA\nAAAAAAEDBAUC/8QAIxEAAgICAgIBBQAAAAAAAAAAAAECEQMEEjEhQVEFEyIz\ngf/aAAwDAQACEQMRAD8AKmlVT7Q9oF4sGqV223NxFthpC0hxoqUSQSeO8O6o\ncvbbd23ktO/w5LiuASWFDP8AmrlzivDY+LqwiaVDwNt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).then(response => {
* console.info(response.data);
* }).catch(err => {
* console.error(err);
* });
* Output:
*
* {
* "id": 4387,
* "product_id": 1,
* "external_id": null,
* "position": 1,
* "created_at": "2026-10-21T23:12:43.000+03:00",
* "image_processing": true,
* "title": null,
* "url": "/images/loading.gif",
* "original_url": "/images/loading.gif",
* "medium_url": "/images/loading.gif",
* "small_url": "/images/loading.gif",
* "thumb_url": "/images/loading.gif",
* "compact_url": "/images/loading.gif",
* "large_url": "/images/loading.gif",
* "filename": "image.jpg",
* "has_bitmap_image": false,
* "image_content_type": "image/jpeg"
* }
* @param {Object} options
* @param {string} options.token Required, access token for shop
* @param {string} options.url Required, shop url
* @param {number|string} options.productid Required, product id
* @param {object} options.productimage Required, product image
* @param {Number|String} id Required, app id
* @returns {Promise}
*/
export function createProductImage(options, id) {
return post({
id,
token: options.token,
url: options.url,
api: `products/${options.productid}/images`,
obj: options.productimage
});
}
/**
* DELETE /admin/products/{product_id}/images/{image_id}.json
*
* Examples:
*
* insales.removeProductImage({
* token: '1234567890',
* url: 'shop-test.myinsales.ru',
* productid: '1',
* productimageid: '4419'
* }).then(response => {
* console.info(response.data);
* }).catch(err => {
* console.error(err);
* });
* Output:
*
* {
* "status": "ok"
* }
* @param {Object} options
* @param {string} options.token Required, access token for shop
* @param {string} options.url Required, shop url
* @param {number|string} options.productid Required, product id
* @param {number|string} options.productimageid Required, product image id
* @param {Number|String} id Required, app id
* @returns {Promise}
*/
export function removeProductImage(options, id) {
return remove({
id,
token: options.token,
url: options.url,
api: `products/${options.productid}/images/${options.productimageid}`
});
}
/**
* PUT /admin/products/{product_id}/images/{image_id}.json
*
* Examples:
*
* insales.editProductImage({
* token: '1234567890',
* url: 'shop-test.myinsales.ru',
* productid: '1',
* productimageid: '4403',
* productimage: {
* "image": {
* "position": 5,
* "title": "myimage"
* }
* }
* }).then(response => {
* console.info(response.data);
* }).catch(err => {
* console.error(err);
* });
* Output:
*
* {
* "id": 4403,
* "product_id": 1,
* "external_id": null,
* "position": 5,
* "created_at": "2026-10-21T23:12:44.000+03:00",
* "image_processing": true,
* "title": "myimage",
* "url": "/images/loading.gif",
* "original_url": "/images/loading.gif",
* "medium_url": "/images/loading.gif",
* "small_url": "/images/loading.gif",
* "thumb_url": "/images/loading.gif",
* "compact_url": "/images/loading.gif",
* "large_url": "/images/loading.gif",
* "filename": "image.jpg",
* "has_bitmap_image": false,
* "image_content_type": "image/jpeg"
* }
* @param {Object} options
* @param {string} options.token Required, access token for shop
* @param {string} options.url Required, shop url
* @param {number|string} options.productid Required, product id
* @param {number|string} options.productimageid Required, product image id
* @param {object} options.productimage Required, product image
* @param {Number|String} id Required, app id
* @returns {Promise}
*/
export function editProductImage(options, id) {
return put({
id,
token: options.token,
url: options.url,
api: `products/${options.productid}/images/${options.productimageid}`,
obj: options.productimage
});
}