Currencies
This article contains all actions for retrieving and managing currencies.
Get currency by ID#
query {
getLocaleCurrency(id: "EUR") {
id
label
status
mtime
ctime
editor
}
}
const body = JSON.stringify({'query':
`query {
getLocaleCurrency(id: "EUR") {
id
label
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": {
"getLocaleCurrency": {
"id": "EUR",
"label": "Euro",
"status": 1,
"mtime": "2022-05-28 06:26:34",
"ctime": "2022-05-28 06:26:34",
"editor": "setup"
}
}
}
Search currencies#
The filter parameter is explained in the filter section of the GraphQL basics article.
query {
searchLocaleCurrencys(filter: "{\"==\": {\"locale.currency.status\":1}}") {
id
label
status
mtime
ctime
editor
}
}
let filter = {
"==": {"locale.currency.status":1}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
searchLocaleCurrencys(filter: ` + fstr + `) {
id
label
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": {
"searchLocaleCurrencys": [
{
"id": "EUR",
"label": "Euro",
"status": 1,
"mtime": "2022-05-28 06:26:34",
"ctime": "2022-05-28 06:26:34",
"editor": "setup"
},
{
"id": "USD",
"label": "US dollar",
"status": 1,
"mtime": "2022-05-28 06:26:35",
"ctime": "2022-05-28 06:26:35",
"editor": "setup"
}
]
}
}
Save single currency#
mutation {
saveLocaleCurrency(input: {
code: "XH1"
label: "Test currency"
}) {
id
}
}
const body = JSON.stringify({'query':
`mutation {
saveLocaleCurrency(input: {
code: "XH1"
label: "Test currency"
}) {
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": {
"saveLocaleCurrency": {
"id": "XH1"
}
}
}
Save multiple currencies#
mutation {
saveLocaleCurrencys(input: [{
code: "XH2"
label: "Test currency 2"
},{
code: "XH3"
label: "Test currency 3"
}]) {
id
}
}
const body = JSON.stringify({'query':
`mutation {
saveLocaleCurrencys(input: [{
code: "XH2"
label: "Test currency 2"
},{
code: "XH3"
label: "Test currency 3"
}]) {
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": {
"saveLocaleCurrencys": [
{
"id": "XH2"
},
{
"id": "XH3"
}
]
}
}
Delete single currency#
mutation {
deleteLocaleCurrency(id: "XH1")
}
const body = JSON.stringify({'query':
`mutation {
deleteLocaleCurrency(id: "XH1")
}`});
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": {
"deleteLocaleCurrency": "XH1"
}
}
Delete multiple currencies#
mutation {
deleteLocaleCurrencys(id: ["XH2", "XH3"])
}
const body = JSON.stringify({'query':
`mutation {
deleteLocaleCurrencys(id: ["XH2", "XH3"])
}`});
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": {
"deleteLocaleCurrencys": [
"XH2",
"XH3"
]
}
}