Zubda
Zubda

Reputation: 963

Create Shopify product with Variant SKU using API

I am trying to create Products on Shopify using the API, In the CSV upload there is a field Variant SKU which sets the (default) product SKU, I can't seem to find the correct way to create a product along with this value?

I tried (python3);

import requests
import json
from config import SHOPIFY_URL

payload = {
    'product': {
        'title': 'Hello Product',
        'variants': {
            'option1': 'Primary',
            'sku': 'hello-product'
        }
    }
}

requests.post(
    f'{SHOPIFY_URL}/products.json',
    headers = {'content-type': 'application/json'},
    data=json.dumps(payload)
)

The product get created but the SKU doesn't.

The TL;DR of my question;
What to I need to pass to fill the Product CSV Upload file's field Variant SKU?

Update

Thanks to David Lazar's comments, I realized that I need to use a list of variants.

payload = {
    'product': {
        'title': 'Hello Product',
        'variants': [
            {
                'option1': 'Primary',
                'sku': 'hello-product'
            }
        ]
    }
}

This however creates the product with one variant using the passed SKU.
However what I am looking is to create the Porduct with its own SKU, no variations for the product, just a SKU for the product.

Upvotes: 0

Views: 1760

Answers (1)

Luc
Luc

Reputation: 1

If you remove the option1 field from your single variant it will update the Product SKU.

Upvotes: 0

Related Questions