Skip to content

Services

This article contains all actions for retrieving and managing services.

Tip

The service domain supports fetching related resources.

Get service by ID#

query {
  getService(id: "1", include: ["text"]) {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
  }
}
Aimeos.query(`query {
  getService(id: "1", include: ["text"]) {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`query {
  getService(id: "1", include: ["text"]) {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
  }
}`});

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": {
    "getService": {
      "id": "1",
      "siteid": "1.",
      "type": "payment",
      "code": "paypalplus",
      "label": "PPPlus",
      "provider": "PaypalPlus",
      "datestart": null,
      "dateend": null,
      "config": "{\\"authorize\\":0,\\"clientid\\":0,\\"secret\\":0,\\"testmode\\":0}",
      "position": "0",
      "status": 1,
      "mtime": "2022-06-08 16:11:10",
      "ctime": "2022-06-08 16:11:10",
      "editor": "aimeos@aimeos.org",
      "lists": {
        "text": [{
          "id": "1",
          "item": {
            "id": "10",
            "content": "Test content"
          }
        }]
      }
    }
  }
}

Find service by code#

query {
  findService(code: "paypalplus", include: ["text"]) {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
  }
}
Aimeos.query(`query {
  findService(code: "paypalplus", include: ["text"]) {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`query {
  findService(code: "paypalplus", include: ["text"]) {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
  }
}`});

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": {
    "findService": {
      "id": "1",
      "siteid": "1.",
      "type": "payment",
      "code": "paypalplus",
      "label": "PPPlus",
      "provider": "PaypalPlus",
      "datestart": null,
      "dateend": null,
      "config": "{\\"authorize\\":0,\\"clientid\\":0,\\"secret\\":0,\\"testmode\\":0}",
      "position": "0",
      "status": 1,
      "mtime": "2022-06-08 16:11:10",
      "ctime": "2022-06-08 16:11:10",
      "editor": "aimeos@aimeos.org",
      "lists": {
        "text": [{
          "id": "1",
          "item": {
            "id": "10",
            "content": "Test content"
          }
        }]
      }
    }
  }
}

Search services#

The filter parameter is explained in the filter section of the GraphQL basics article.

query {
  searchServices(filter: "{\\"=~\\": {\\"service.code\\":\\"demo-\\"}}", include: ["text"]) {
    items {
      id
      siteid
      type
      code
      label
      provider
      datestart
      dateend
      config
      position
      status
      mtime
      ctime
      editor
      lists {
        text {
          id
          item {
            id
            content
          }
        }
      }
    }
    total
  }
}
Aimeos.query(`query {
  searchServices(filter: "{\\"=~\\": {\\"service.code\\":\\"demo-\\"}}", include: ["text"]) {
    items {
      id
      siteid
      type
      code
      label
      provider
      datestart
      dateend
      config
      position
      status
      mtime
      ctime
      editor
      lists {
        text {
          id
          item {
            id
            content
          }
        }
      }
    }
    total
  }
}`).then(data => {
  console.log(data)
})
let filter = {
    "=~": {"service.code":"demo-"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
  searchServices(filter: ` + fstr + `, include: ["text"]) {
    items {
      id
      siteid
      type
      code
      label
      provider
      datestart
      dateend
      config
      position
      status
      mtime
      ctime
      editor
      lists {
        text {
          id
          item {
            id
            content
          }
        }
      }
    }
    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": {
    "searchServices": {
      "items": [
        {
          "id": "1",
          "siteid": "1.",
          "type": "delivery",
          "code": "demo-pickup",
          "label": "Click & Collect",
          "provider": "Standard,Time,Supplier",
          "datestart": null,
          "dateend": null,
          "config": "{}",
          "position": 0,
          "status": 1,
          "mtime": "2022-12-01 11:59:07",
          "ctime": "2022-12-01 11:59:07",
          "editor": "core",
          "lists": {
            "text": [{
              "id": "1",
              "item": {
                "id": "10",
                "content": "Test content"
              }
            }]
          }
        },
        {
          "id": "2",
          "siteid": "1.",
          "type": "delivery",
          "code": "demo-dhl",
          "label": "DHL",
          "provider": "Standard",
          "datestart": null,
          "dateend": null,
          "config": "{}",
          "position": 1,
          "status": 1,
          "mtime": "2022-12-01 11:59:07",
          "ctime": "2022-12-01 11:59:07",
          "editor": "core",
          "lists": {
            "text": []
          }
        }
      ],
      "total": 2
    }
  }
}

Fetch service configuration#

To retrieve the backend configuration for a service provider and the added decorators use:

query {
  getServiceConfig(provider: "Xml,BasketValues", type: "delivery") {
    code
    type
    label
  }
}
Aimeos.query(`query {
  getServiceConfig(provider: "Xml,BasketValues", type: "delivery") {
    code
    type
    label
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`query {
  getServiceConfig(provider: "Xml,BasketValues", type: "delivery") {
    code
    type
    label
  }
}`});

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": {
    "getServiceConfig": [
      {
        "code":"xml.backupdir",
        "type":"string",
        "label":"Relative or absolute path of the backup directory (with date() placeholders)"
      },{
        "code":"xml.exportpath",
        "type":"string",
        "label":"Relative or absolute path and name of the XML files (with date() placeholders)"
      },{
        "code":"xml.template",
        "type":"string",
        "label":"Relative path of the template file name"
      },{
        "code":"xml.updatedir",
        "type":"string",
        "label":"Relative or absolute path and name of the order update XML files"
      },{
        "code":"basketvalues.total-value-min",
        "type":"map",
        "label":"Minimum total value of the basket"
      },{
        "code":"basketvalues.total-value-max",
        "type":"map",
        "label":"Maximum total value of the basket"
      }
    ]
  }
}

Save single service#

mutation {
  saveService(input: {
    type: "delivery"
    code: "test"
    label: "Test service"
    provider: "Standard",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    }
  }) {
    id
  }
}
Aimeos.query(`mutation {
  saveService(input: {
    type: "delivery"
    code: "test"
    label: "Test service"
    provider: "Standard",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    }
  }) {
    id
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
  saveService(input: {
    type: "delivery"
    code: "test"
    label: "Test service"
    provider: "Standard",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    }
  }) {
    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": {
    "saveService": {
      "id": "13"
    }
  }
}

Save multiple services#

mutation {
  saveServices(input: [{
    type: "delivery"
    code: "test-2"
    label: "Test 2 service"
    provider: "Xml",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    }
  },{
    type: "payment"
    code: "test-3"
    label: "Test 3 service"
    provider: "PostPay"
  }]) {
    id
  }
}
Aimeos.query(`mutation {
  saveServices(input: [{
    type: "delivery"
    code: "test-2"
    label: "Test 2 service"
    provider: "Xml",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    }
  },{
    type: "payment"
    code: "test-3"
    label: "Test 3 service"
    provider: "PostPay"
  }]) {
    id
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
  saveServices(input: [{
    type: "delivery"
    code: "test-2"
    label: "Test 2 service"
    provider: "Xml",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    }
  },{
    type: "payment"
    code: "test-3"
    label: "Test 3 service"
    provider: "PostPay"
  }]) {
    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": {
    "saveServices": [
      {
        "id": "14"
      },
      {
        "id": "15"
      }
    ]
  }
}

Delete single service#

mutation {
  deleteService(id: "13")
}
Aimeos.query(`mutation {
  deleteService(id: "13")
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
  deleteService(id: "13")
}`});

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": {
    "deleteService": "13"
  }
}

Delete multiple services#

mutation {
  deleteServices(id: ["14", "15"])
}
Aimeos.query(`mutation {
  deleteServices(id: ["14", "15"])
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
  deleteServices(id: ["14", "15"])
}`});

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": {
    "deleteServices": [
      "14",
      "15"
    ]
  }
}

Comments

Become an Aimeos Partner

Aimeos partners are first-class specialists in creating or hosting your Aimeos e-commerce project. They have proven their expertise by building top level e-commerce applications using Aimeos.