Development discussions around Shopify APIs
Hi,
I have i problem with creating a product with its images using the API 2021-01.
The images array is sometimes empty in the returned result,
Here's my schema tha i send to "https://shopname.myshopify.com/admin/api/2021-01/products.json" :
return empty images
The product is added successfully but without images or image
Using the REST API, I believe you need to first create the new image and then create the new product/variant and assign the image to the new record. With the GraphQL API you can likely create everything all in one shot. Using the REST API, not so much...
I am a beginner, can you give me an example of code, in order to understand more easily
can you tell me how to use graphQL create product with images in variant,Can you give me a code example
Hey there,
Response to:
@HMM100 wrote:can you tell me how to use graphQL create product with images in variant,Can you give me a code example
this is what I've learned when working with the GraphQL API. It is possible to create a product with images. I will also add the information on how to create a product with an image and variants that also have those images assigned because it is related.
If you don't know how to use the GraphQL API you can checkout the following resources:
mutation productCreate($input:ProductInput!) {
productCreate(input: $input) {
product {
title
}
}
}
Notice: You don't have to mention the image attribute in the query, because what you define with it, is the response the request delivers and not the request itself...
2. Create the object you will send to the GraphQL API
{
"title": "Test product",
"options": [
"NewOption",
],
"images": [
{
"src": "https://cdn.shopify.com/s/files/1/0609/3242/3910/products/download_0e944bb8-3b3e-499d-899d-95e1eb03fa42.jpg?v=1636291618"
},
{
"src": "https://cdn.shopify.com/s/files/1/0609/3242/3910/products/download.jpg?v=1636291617"
}
]
"variants": [
{
"price": 20,
"sku": "SKU_01",
"barcode": "1",
"imageSrc": "https://cdn.shopify.com/s/files/1/1234/1234/1234/products/picture1.jpg?v=12345678",
"options": [
"Option value",
],
"title": "title1",
"position": 1
},
{
"price": 20,
"sku": "SKU_02",
"barcode": "2",
"imageSrc": "https://cdn.shopify.com/s/files/1/1234/1234/1234/products/picture2.jpg?v=1636291617",
"options": [
"Other option value"
],
"title": "title2",
"position": 2
}
]
}
That's it. Here are some other resources that may help you:
I hope I could help!
User | RANK |
---|---|
8 | |
7 | |
3 | |
3 | |
3 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By