GraphQL : How to know sales channels ID and mutaion to add a new prodcut

GraphQL : How to know sales channels ID and mutaion to add a new prodcut

heyuuuuu
Tourist
22 0 1

I want to create prodcut with sales channel ID using Python and GraphQL API.

heyuuuuu_0-1699533783355.png

 

But I don't know how to know sales channel ID for first.

 

So, please tell me how to get to know sales channel ID using GQL query and then if possible, 

tell me how to create a product with sales channel using Python and GraphQL.

 

GQL query

 

 

sorry I have no idea

 

 

 

Python code 

maybe its gonna be like this

import requests
import json

# Shopify API credentials
shop_url = "SHOP_URL"
access_token = "ACCESS_TOKEN"

# GraphQL endpoint
graphql_url = f"{shop_url}/admin/api/2023-10/graphql.json"

# Build the GraphQL mutation
mutation = """
GQL query 
"""

headers = {
    "Content-Type": "application/json",
    "X-Shopify-Access-Token": access_token,
}


# Create the request data
data = {
    "query": mutation,
}

response = requests.post(graphql_url, json=data, headers=headers)

if response.status_code == 200:
    result = response.json()
    print("Product with options and option values created:")
    print(json.dumps(result, indent=2))
else:
    print(f"Failed to create the product. Status Code: {response.status_code}")
    print(response.text)

 

 

 

Reply 1 (1)

SBD_
Shopify Staff
1829 271 413

Hey @heyuuuuu 

 

I can't help with the Python code, but you'll want to use this mutation (scroll down for an example).

 

You can get the IDs here.

Scott | Developer Advocate @ Shopify