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
}
}
Aimeos.query(`query {
getLocaleCurrency(id: "EUR") {
id
label
status
mtime
ctime
editor
}
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`query {
getLocaleCurrency(id: "EUR") {
id
label
status
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": {
"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}}") {
items {
id
label
status
mtime
ctime
editor
}
total
}
}
Aimeos.query(`query {
searchLocaleCurrencys(filter: "{\\"==\\": {\\"locale.currency.status\\":1}}") {
items {
id
label
status
mtime
ctime
editor
}
total
}
}`).then(data => {
console.log(data)
})
let filter = {
"==": {"locale.currency.status":1}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
searchLocaleCurrencys(filter: ` + fstr + `) {
items {
id
label
status
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": {
"searchLocaleCurrencys": {
"items": [
{
"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"
}
],
"total": 2
}
}
}
Save single currency#
mutation {
saveLocaleCurrency(input: {
code: "XH1"
label: "Test currency"
}) {
id
}
}
Aimeos.query(`mutation {
saveLocaleCurrency(input: {
code: "XH1"
label: "Test currency"
}) {
id
}
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
saveLocaleCurrency(input: {
code: "XH1"
label: "Test currency"
}) {
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": {
"saveLocaleCurrency": {
"id": "XH1"
}
}
}
Save multiple currencies#
mutation {
saveLocaleCurrencys(input: [{
code: "XH2"
label: "Test currency 2"
}
{
code: "XH3"
label: "Test currency 3"
}]) {
id
}
}
Aimeos.query(`mutation {
saveLocaleCurrencys(input: [{
code: "XH2"
label: "Test currency 2"
}
{
code: "XH3"
label: "Test currency 3"
}]) {
id
}
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
saveLocaleCurrencys(input: [{
code: "XH2"
label: "Test currency 2"
}
{
code: "XH3"
label: "Test currency 3"
}]) {
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": {
"saveLocaleCurrencys": [
{
"id": "XH2"
},
{
"id": "XH3"
}
]
}
}
Delete single currency#
mutation {
deleteLocaleCurrency(id: "XH1")
}
Aimeos.query(`mutation {
deleteLocaleCurrency(id: "XH1")
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
deleteLocaleCurrency(id: "XH1")
}`});
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": {
"deleteLocaleCurrency": "XH1"
}
}
Delete multiple currencies#
mutation {
deleteLocaleCurrencys(id: ["XH2", "XH3"])
}
Aimeos.query(`mutation {
deleteLocaleCurrencys(id: ["XH2", "XH3"])
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
deleteLocaleCurrencys(id: ["XH2", "XH3"])
}`});
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": {
"deleteLocaleCurrencys": [
"XH2",
"XH3"
]
}
}