Suppliers
This article contains all actions for retrieving and managing suppliers.
Tip
The supplier domain supports fetching related resources.
Get supplier by ID#
query {
getSupplier(id: "1") {
id
siteid
code
label
position
status
mtime
ctime
editor
}
}
const body = JSON.stringify({'query':
`query {
getSupplier(id: "1") {
id
siteid
code
label
position
status
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": {
"getSupplier": {
"id": "1",
"siteid": "1.",
"code": "demo-test1",
"label": "Test supplier 1",
"position": 0,
"status": 1,
"mtime": "2022-12-01 11:59:04",
"ctime": "2022-12-01 11:59:04",
"editor": "core"
}
}
}
Find supplier by code#
query {
findSupplier(code: "demo-test1") {
id
siteid
code
label
position
status
mtime
ctime
editor
}
}
const body = JSON.stringify({'query':
`query {
findSupplier(code: "demo-test1") {
id
siteid
code
label
position
status
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": {
"findSupplier": {
"id": "1",
"siteid": "1.",
"code": "demo-test1",
"label": "Test supplier 1",
"position": 0,
"status": 1,
"mtime": "2022-12-01 11:59:04",
"ctime": "2022-12-01 11:59:04",
"editor": "core"
}
}
}
Search suppliers#
The filter parameter is explained in the filter section of the GraphQL basics article.
query {
searchSuppliers(filter: "{\"=~\": {\"supplier.code\":\"demo-\"}}") {
id
siteid
code
label
position
status
mtime
ctime
editor
}
}
let filter = {
"=~": {"supplier.code":"demo-"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
searchSuppliers(filter: ` + fstr + `) {
id
siteid
code
label
position
status
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": {
"searchSuppliers": [
{
"id": "1",
"siteid": "1.",
"code": "demo-test1",
"label": "Test supplier 1",
"position": 0,
"status": 1,
"mtime": "2022-12-01 11:59:04",
"ctime": "2022-12-01 11:59:04",
"editor": "core"
},
{
"id": "2",
"siteid": "1.",
"code": "demo-test2",
"label": "Test supplier 2",
"position": 0,
"status": 1,
"mtime": "2022-12-01 11:59:04",
"ctime": "2022-12-01 11:59:04",
"editor": "core"
}
]
}
}
Save single supplier#
mutation {
saveSupplier(input: {
code: "test"
label: "Test supplier"
}) {
id
}
}
const body = JSON.stringify({'query':
`mutation {
saveSupplier(input: {
code: "test"
label: "Test supplier"
}) {
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": {
"saveSupplier": {
"id": "3"
}
}
}
Save multiple suppliers#
mutation {
saveSuppliers(input: [{
code: "test-2"
label: "Test 2 supplier"
},{
code: "test-3"
label: "Test 3 supplier"
}]) {
id
}
}
const body = JSON.stringify({'query':
`mutation {
saveSuppliers(input: [{
code: "test-2"
label: "Test 2 supplier"
},{
code: "test-3"
label: "Test 3 supplier"
}]) {
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": {
"saveSuppliers": [
{
"id": "4"
},
{
"id": "5"
}
]
}
}
Delete single supplier#
mutation {
deleteSupplier(id: "3")
}
const body = JSON.stringify({'query':
`mutation {
deleteSupplier(id: "3")
}`});
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": {
"deleteSupplier": "3"
}
}
Delete multiple suppliers#
mutation {
deleteSuppliers(id: ["4", "5"])
}
const body = JSON.stringify({'query':
`mutation {
deleteSuppliers(id: ["4", "5"])
}`});
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": {
"deleteSuppliers": [
"4",
"5"
]
}
}