I am currently working on creating products via the Shopify API, and I am facing an issue with uploading an image and attaching it to the product using the GraphQL API.
I have a working implementation using the REST API, where I can encode the image as base64 and directly upload it while creating the product. The image is successfully processed and attached to the product, and I am able to retrieve the image URL.
However, I am now trying to achieve the same functionality using the GraphQL API. I am creating the product first, but I am unsure how to upload the image and attach it to the product properly. I attempted to use the productCreateMedia
mutation for image uploading, but I am not getting the expected result.
Could you please provide guidance on:
- The correct steps to upload an image to a product using the GraphQL API.
- How to encode the image (base64) or attach the image using a URL directly through GraphQL.
- How to retrieve and save the image URL once the image is uploaded successfully.
If any specific mutation or API call should be used in this process, could you provide an example?