Development discussions around Shopify APIs
Hi I was trying to change an image src from a product using PHP and GraphQL API, but I am having problems with the declaration of varibles and the access.
here is my code:
----------------------------------
Using GQL the process of assigning a new image to a product involves a few steps. For example, below is my Postman test of your API request that's giving you trouble. I pointed the productId to a valid one in my test shop. Note the API response. The image being assigned to a specific product likely needs to already be defined in Shopify. So you'd need to perform the initial step of uploading it in Shopify so that it's already defined by an ImageId. This is once you get past the PHP parsing issues that Shopify is complaining about...
Hi Greg! Thanks for the quick answer.
I thought I had a problem with the ID for the new Images. But my biggest issue is the GQL parsing complaining. I would like to know how to declare variables in the query.
I did found a way around it by declaring the variables in php and then implementing a function in the POSTFIELDS. But I would like to know how do it without it.
regards!
When I run test GQL API requests in Postman, I have the Content-Type defined as application/json. Here's how the raw data looks as captured with Fiddler. Maybe this helps a little more?
POST https://{my_shop}.myshopify.com/admin/api/2020-10/graphql.json HTTP/1.1
X-Shopify-Access-Token: {my_token}
Content-Type: application/json
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Postman-Token: 47556ad1-c432-4bce-bc52-fa6ec9c6ee5b
Host: {my_shop}.myshopify.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 417
Cookie: xxxx
{"query":" mutation productImageUpdate($productId: ID!, $image: ImageInput!) {\r\n productImageUpdate(productId: $productId, image: $image) {\r\n image {\r\n id\r\n }\r\n userErrors {\r\n field\r\n message\r\n }\r\n }\r\n }\r\n\r\n","variables":{
"productId": "gid://shopify/Product/4423635632180",
"image": { "src" : "https://picsum.photos/200/300"}
}}
Thanks Greg! I will let you know how it goes. 😉
User | RANK |
---|---|
10 | |
4 | |
3 | |
3 | |
3 |
As a business owner, have you ever wondered when your customer's first impression of yo...
By Skye Jun 6, 2023We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023