I have to move products from one Shopify store to another. To do this I am using the Shopify GraphQL admin API. I am transforming the data before moving it so I can’t have Shopify help me.
Anyway, I take the products from Shopify’s API and they’re store in a JSON file. Each product is around 3,000 lines long and contains all variant types.
Do I have to define the query fields and variables? I was hoping to just pass in the entire JSON object that Shopify returns and feed that to GraphQL. Currently I’m having to do define the fields manually (NodeJS):
const addProduct = (product) => axios.post(apiPath, {
query: `
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
title
handle
descriptionHtml
...
}
}
}
`,
variables: {
input: {...product}
}
})
But having to define the query fields in this way is going to a very long process, is there any way to do without having to define the query?
Here’s an example from the product object from Shopify. I’ve had to limit the lines:
{
"body_html": " The Air Jordan 3 Retro 'UNC' arrives in March 2020 as an homage to Michael Jordan's alma mater. The special edition presents university-inspired colors on its dual-textured leather upper and eyestays, with elephant print panels granting an iconic touch. Valor Blue hits both Jumpman logos on the tongue and heel while the visible Air unit in the midsole and rubber outsole wrap up the styling. ",
"price_min_usd": 0,
"compare_at_price_max_usd": null,
"available": false,
"review_count": 0,
"percent_sale_min_aud": 0,
"variants": [
{
"merged_options": [
"size:3 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "CAD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "DKK"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "EUR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "GBP"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "ILS"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0",
"currency_code": "JPY"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "QAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "SAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "USD"
}
}
],
"inventory_management": "shopify",
"available": false,
"title": "UK 3 | EU 35.5 | US 3.5",
"price": "0.00",
"price_aed": "0.00",
"id": 40807884062909,
"sku": "CT8532-104.3UK",
"price_eur": "0.00",
"barcode": null,
"price_dkk": "0.00",
"inventory_quantity": 0,
"image": null,
"compare_at_price": null,
"fulfillment_service": "manual",
"price_aud": "0.00",
"price_ils": "0.00",
"price_jpy": "0",
"inventory_policy": "deny",
"price_gbp": "0.00",
"price_qar": "0.00",
"price_sar": "0.00"
},
{
"merged_options": [
"size:3.5 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "CAD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "DKK"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "EUR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "GBP"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "ILS"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0",
"currency_code": "JPY"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "QAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "SAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "USD"
}
}
],
"inventory_management": "shopify",
"available": false,
"title": "UK 3.5 | EU 36 | US 4",
"price": "0.00",
"price_aed": "0.00",
"id": 40807884095677,
"sku": "CT8532-104.3.5UK",
"price_eur": "0.00",
"barcode": null,
"price_dkk": "0.00",
"inventory_quantity": 0,
"image": null,
"compare_at_price": null,
"fulfillment_service": "manual",
"price_aud": "0.00",
"price_ils": "0.00",
"price_jpy": "0",
"inventory_policy": "deny",
"price_gbp": "0.00",
"price_qar": "0.00",
"price_sar": "0.00"
},
{
"merged_options": [
"size:4 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
2
Answers
@BugHunterUK – As per my understanding you’re moving products data from one store to another with JSON file but you don’t have do it. You can ask Shopify Support to do that. They will move all of your products from store A to B.
An easy recipe is to download a product where you get valid Shopify Product JSON. Now remove all the id keys. Send that object to the Product Create in the new store. Repeat in a loop.
You could also bulk download the products, giving you JSON, and iterate that, and build products that way, and call create.
Either way, the code to do this task is short, sweet and not hard.