Products
This article contains all actions for retrieving and managing products.
Tip
The product domain supports fetching related resources.
Get product by ID#
query {
getProduct(id: "1") {
id
siteid
type
code
label
url
dataset
datestart
dateend
config
instock
scale
status
target
boost
mtime
ctime
editor
}
}
const body = JSON.stringify({'query':
`query {
getProduct(id: "1") {
id
siteid
type
code
label
url
dataset
datestart
dateend
config
instock
target
scale
status
boost
mtime
ctime
editor
}
}`});
fetch($('.aimeos').data('graphql'), {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"getProduct": {
"id": "113",
"siteid": "1.",
"type": "default",
"code": "demo-article",
"label": "Demo article",
"url": "demo-article",
"dataset": null,
"datestart": null,
"dateend": null,
"config": "{}",
"instock": null,
"target": null,
"scale": 1,
"status": 1,
"boost": 1,
"mtime": "2023-01-13 11:25:51",
"ctime": "2022-12-01 11:59:00",
"editor": "aimeos@aimeos.org"
}
}
}
Find product by code#
query {
findProduct(code: "demo-article") {
id
siteid
type
code
label
url
dataset
datestart
dateend
config
instock
scale
status
target
boost
mtime
ctime
editor
}
}
const body = JSON.stringify({'query':
`query {
findProduct(code: "demo-article") {
id
siteid
type
code
label
url
dataset
datestart
dateend
config
instock
scale
status
target
boost
mtime
ctime
editor
}
}`});
fetch($('.aimeos').data('graphql'), {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"findProduct": {
"id": "1",
"siteid": "1.",
"type": "default",
"code": "demo-article",
"label": "Demo article",
"url": "demo-article",
"dataset": null,
"datestart": null,
"dateend": null,
"config": "{}",
"instock": null,
"scale": 1,
"status": 1,
"target": null,
"boost": 1,
"mtime": "2023-01-13 11:25:51",
"ctime": "2022-12-01 11:59:00",
"editor": "aimeos@aimeos.org"
}
}
}
Search products#
The filter parameter is explained in the filter section of the GraphQL basics article.
query {
searchProducts(filter: "{\"=~\": {\"product.code\":\"demo-\"}}") {
id
siteid
type
code
label
url
dataset
datestart
dateend
config
instock
scale
status
target
boost
mtime
ctime
editor
}
}
let filter = {
"=~": {"product.code":"demo-"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
searchProducts(filter: ` + fstr + `) {
id
siteid
type
code
label
url
dataset
datestart
dateend
config
instock
scale
status
target
boost
mtime
ctime
editor
}
}`});
fetch($('.aimeos').data('graphql'), {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"searchProducts": [
{
"id": "1",
"siteid": "1.",
"type": "default",
"code": "demo-article",
"label": "Demo article",
"url": "demo-article",
"dataset": null,
"datestart": null,
"dateend": null,
"config": "{}",
"instock": null,
"scale": 1,
"status": 1,
"target": null,
"boost": 1,
"mtime": "2023-01-13 11:25:51",
"ctime": "2022-12-01 11:59:00",
"editor": "aimeos@aimeos.org"
},
{
"id": "2",
"siteid": "1.",
"type": "default",
"code": "demo-selection-article-1",
"label": "Demo variant article 1",
"url": "demo-variant-article-1",
"dataset": null,
"datestart": null,
"dateend": null,
"config": "{}",
"instock": null,
"scale": 1,
"status": 1,
"target": null,
"boost": 1,
"mtime": "2022-12-01 11:59:05",
"ctime": "2022-12-01 11:59:05",
"editor": "core"
}
]
}
}
Save single product#
mutation {
saveProduct(input: {
code: "test"
label: "Test product"
}) {
id
}
}
const body = JSON.stringify({'query':
`mutation {
saveProduct(input: {
code: "test"
label: "Test product"
}) {
id
}
}`});
fetch($('.aimeos').data('graphql'), {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"saveProduct": {
"id": "18"
}
}
}
Save multiple products#
mutation {
saveProducts(input: [{
code: "test-2"
label: "Test 2 product"
},{
code: "test-3"
label: "Test 3 product"
}]) {
id
}
}
const body = JSON.stringify({'query':
`mutation {
saveProducts(input: [{
code: "test-2"
label: "Test 2 product"
},{
code: "test-3"
label: "Test 3 product"
}]) {
id
}
}`});
fetch($('.aimeos').data('graphql'), {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"saveProducts": [
{
"id": "19"
},
{
"id": "20"
}
]
}
}
Delete single product#
mutation {
deleteProduct(id: "18")
}
const body = JSON.stringify({'query':
`mutation {
deleteProduct(id: "18")
}`});
fetch($('.aimeos').data('graphql'), {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"deleteProduct": "18"
}
}
Delete multiple products#
mutation {
deleteProducts(id: ["19", "20"])
}
const body = JSON.stringify({'query':
`mutation {
deleteProducts(id: ["19", "20"])
}`});
fetch($('.aimeos').data('graphql'), {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"deleteProducts": [
"19",
"20"
]
}
}