Personalized checkout and custom promotions with Shopify Scripts
Hi all,
I am creating a product throught my CMS to be added in shopify for the checkout:
const mutation = `
mutation CreateProduct($product:ProductCreateInput) {
productCreate(product: $product) {
product {
id
title
descriptionHtml
productType
vendor
handle
}
userErrors {
field
message
}
}
}`
const { data, errors } = await getGraphQLClient().request(mutation, {
variables: {
product: {
title: product.title,
productType: product.productType,
descriptionHtml: product.descriptionHtml,
vendor: 'myShop',
handle: product.handle,
},
},
})
after i need to add the price, I got this from the ai asistant(after a lot of suffering and pain)
if (data) {
const priceMutation = `
mutation CreateVariant($input: ProductVariantInput!) {
productVariantCreate(input: $input) {
productVariant {
id
price
}
userErrors {
field
message
}
}
}`
await getGraphQLClient().request(priceMutation, {
variables: {
input: {
productId: data.productCreate.product.id,
price: product.price.toString(),
},
},
})
then i add an image
const uploadImageMutation = `
mutation UploadImage($productId: ID!, $media: [CreateMediaInput!]!) {
productCreateMedia(productId: $productId, media: $media) {
media {
status
alt
preview {
image {
url
}
}
}
userErrors {
field
message
}
}
}
`
await getGraphQLClient().request(uploadImageMutation, {
variables: {
productId: data.productCreate.product.id,
media: [
{
originalSource: product.imageUrl,
mediaContentType: 'IMAGE',
alt: product.title,
},
],
},
})
the problem is that in my shopify store, I am able to see the product created, the image but not the price(it shows '0').
is there something I am missing?
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025