Managing product templates
Introduction
This guide describes how to query, create, and update product templates from the Traide GraphQL API.
Query product templates
{
productTypes(first: 100) {
edges {
node {
id
name
}
}
}
}
Response:
{
"data": {
"productTypes": {
"edges": [
{
"node": {
"id": "UHJvZHVjdFR5cGU6MTg=",
"name": "Apparel"
}
},
{
"node": {
"id": "UHJvZHVjdFR5cGU6Ng==",
"name": "Supplements"
}
}
]
}
}
}
Show more ↓
Create a product template
Use the productTypeCreate mutation.
mutation {
productTypeCreate(input: { name: "Apparel" }) {
productType {
id
name
slug
hasVariants
isShippingRequired
productAttributes {
id
name
}
variantAttributes {
id
name
}
weight {
unit
value
}
}
productErrors {
field
code
message
attributes
}
}
}
Show more ↓
Response:
{
"data": {
"productTypeCreate": {
"productType": {
"id": "UHJvZHVjdFR5cGU6MTg=",
"name": "Apparel",
"slug": "apparel",
"hasVariants": true,
"isShippingRequired": true,
"productAttributes": [],
"variantAttributes": [],
"weight": {
"unit": "KG",
"value": 0
}
},
"productErrors": []
}
}
}
Show more ↓
Update a product template
In order to update a product template, you'll need its ID. In our example, it is "UHJvZHVjdFR5cGU6MTg=". Here is an example of updating a product template.
Here's an example of the productTypeUpdate mutation:
mutation {
productTypeUpdate(
id: "UHJvZHVjdFR5cGU6MTg="
input: { hasVariants: false, weight: 10, slug: "a-new-slug" }
) {
productType {
id
name
slug
hasVariants
isShippingRequired
productAttributes {
id
name
}
variantAttributes {
id
name
}
weight {
unit
value
}
}
productErrors {
field
code
message
attributes
}
}
}
Show more ↓
Response:
{
"data": {
"productTypeUpdate": {
"productType": {
"id": "UHJvZHVjdFR5cGU6MTg=",
"name": "Apparel",
"slug": "a-new-slug",
"hasVariants": false,
"isShippingRequired": true,
"productAttributes": [],
"variantAttributes": [],
"weight": {
"unit": "KG",
"value": 10
}
},
"productErrors": []
}
}
}
Show more ↓