upload_product_image
Attach a product image from a public URL to an existing Shopify product. Each call adds a new image without removing existing ones.
Instructions
Attach an image to an existing product by URL. Shopify fetches the URL server-side and hosts the file on its CDN — the URL must be publicly reachable from Shopify's network. Multiple calls add multiple images; this tool does not replace existing images. Use the bridge tools (generate_product_image, refine_product_image) instead when you want the image generated by ComfyUI rather than provided as a URL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| product_id | Yes | Product GID or numeric ID | |
| image_url | Yes | Public image URL to attach | |
| alt_text | No |
Implementation Reference
- src/shopify/upload.ts:30-79 (helper)The stagedUploadImage helper for uploading raw image bytes to Shopify's staged storage (used by bridge tools, not upload_product_image directly).
export async function stagedUploadImage( client: ShopifyClient, bytes: Uint8Array, filename: string, mimeType: string, ): Promise<string> { const data = await client.graphql<{ stagedUploadsCreate: { stagedTargets: StagedTarget[]; userErrors: ShopifyUserError[]; }; }>(STAGED_UPLOADS_CREATE_MUTATION, { input: [ { resource: "IMAGE", filename, mimeType, fileSize: String(bytes.length), httpMethod: "POST", }, ], }); throwIfUserErrors( data.stagedUploadsCreate.userErrors, "stagedUploadsCreate", ); const target = data.stagedUploadsCreate.stagedTargets[0]; if (!target) { throw new Error("stagedUploadsCreate returned no target"); } const form = new FormData(); for (const { name, value } of target.parameters) { form.append(name, value); } form.append("file", new Blob([new Uint8Array(bytes)], { type: mimeType }), filename); const uploadRes = await fetch(target.url, { method: "POST", body: form, }); if (!uploadRes.ok && uploadRes.status !== 201 && uploadRes.status !== 204) { throw new Error( `Shopify staged upload POST failed: ${uploadRes.status} ${await uploadRes.text()}`, ); } return target.resourceUrl; }