Stocks
This article contains all actions for retrieving and managing stocks.
Get stock by ID#
query {
getStock(id: "1") {
id
siteid
type
productid
stocklevel
timeframe
dateback
mtime
ctime
editor
}
}
Aimeos.query(`query {
getStock(id: "1") {
id
siteid
type
productid
stocklevel
timeframe
dateback
mtime
ctime
editor
}
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`query {
getStock(id: "1") {
id
siteid
type
productid
stocklevel
timeframe
dateback
mtime
ctime
editor
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"getStock": {
"id": "1",
"siteid": "1.",
"type": "default",
"productid": "114",
"stocklevel": 5,
"timeframe": "",
"dateback": null,
"mtime": "2022-12-01 11:59:05",
"ctime": "2022-12-01 11:59:05",
"editor": "core"
}
}
}
Search stocks#
The filter parameter is explained in the filter section of the GraphQL basics article.
query {
searchStocks(filter: "{\\"~=\\": {\\"stock.type\\":\\"default\\"}}") {
items {
id
siteid
type
productid
stocklevel
timeframe
dateback
mtime
ctime
editor
}
total
}
}
Aimeos.query(`query {
searchStocks(filter: "{\\"~=\\": {\\"stock.type\\":\\"default\\"}}") {
items {
id
siteid
type
productid
stocklevel
timeframe
dateback
mtime
ctime
editor
}
total
}
}`).then(data => {
console.log(data)
})
let filter = {
"~=": {"stock.type":"default"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
searchStocks(filter: ` + fstr + `) {
items {
id
siteid
type
productid
stocklevel
timeframe
dateback
mtime
ctime
editor
}
total
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"searchStocks": {
"items": [
{
"id": "1",
"siteid": "1.",
"type": "default",
"productid": "114",
"stocklevel": 5,
"timeframe": "",
"dateback": null,
"mtime": "2022-12-01 11:59:05",
"ctime": "2022-12-01 11:59:05",
"editor": "core"
},
{
"id": "12",
"siteid": "1.",
"type": "default",
"productid": "115",
"stocklevel": 0,
"timeframe": "",
"dateback": "2015-01-01 12:00:00",
"mtime": "2022-12-01 11:59:05",
"ctime": "2022-12-01 11:59:05",
"editor": "core"
}
],
"total": 2
}
}
}
Save single stock#
mutation {
saveStock(input: {
type: "warehouse-de"
productid: "1"
stocklevel: 100
}) {
id
}
}
Aimeos.query(`mutation {
saveStock(input: {
type: "warehouse-de"
productid: "1"
stocklevel: 100
}) {
id
}
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
saveStock(input: {
type: "warehouse-de"
productid: "1"
stocklevel: 100
}) {
id
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"saveStock": {
"id": "18"
}
}
}
Save multiple stocks#
mutation {
saveStocks(input: [{
type: "warehouse-fr"
productid: "1"
stocklevel: 50
}
{
type: "warehouse-it"
productid: "1"
stocklevel: 500
}]) {
id
}
}
Aimeos.query(`mutation {
saveStocks(input: [{
type: "warehouse-fr"
productid: "1"
stocklevel: 50
}
{
type: "warehouse-it"
productid: "1"
stocklevel: 500
}]) {
id
}
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
saveStocks(input: [{
type: "warehouse-fr"
productid: "1"
stocklevel: 50
}
{
type: "warehouse-it"
productid: "1"
stocklevel: 500
}]) {
id
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"saveStocks": [
{
"id": "19"
},
{
"id": "20"
}
]
}
}
Delete single stock#
mutation {
deleteStock(id: "18")
}
Aimeos.query(`mutation {
deleteStock(id: "18")
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
deleteStock(id: "18")
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"deleteStock": "18"
}
}
Delete multiple stocks#
mutation {
deleteStocks(id: ["19", "20"])
}
Aimeos.query(`mutation {
deleteStocks(id: ["19", "20"])
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
deleteStocks(id: ["19", "20"])
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"deleteStocks": [
"19",
"20"
]
}
}