Ad

Shopify API - Can't Get Product Image To Store

- 1 answer

I've adapted the phpish/shopify API client (https://github.com/phpish/shopify) to create a simple web form where clients can add products and upload product images to my Shopify store.

I can get the products to add, no problem, but the images just won't upload. I'm using the API to create a new product with the default variant and a base64 encoded image, such as the example below.

Can any body spot what I'm doing wrong?

try
{
    $product = $shopify('POST /admin/products.json', array(), array
    (
        'product' => array
        (
            "title" => "Test Product 2" ,
            "body_html" => "test description" ,
            "vendor" => "URG Trial",
            "variants" => array
            (
                array
                (
                    "price" => "2.50",
                    "sku" => "25",
                                                "weight" => "2",
                                                "weight_unit" => "lb"
                )
            ),
            "images" => array
            (
                                    "attachment" => "/9j/4AAQSkZJRgABAQEAYABgAAD/4QAWRXhpZgAASUkqAAgAAAAAAAAAAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAA5ADIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERU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GjJyh0tL8Hb8dzU0G/1A+Mon1IsbmS4aF0GVCAxkgYPAHA4/Unk+mV5X/wA1k/7e/wD2jXqld2EulJN31Z4mawUZU5LrFP8AMKKKK6zyz//Z==\n"
            ),
        )
    ));

}
Ad

Answer

you forgot that images is one array of arrays, try this for images:

"images" => array(
    array(
        "attachment" => "your_image_base_64"
    )
)
Ad
source: stackoverflow.com
Ad