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") {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
  }
}
const body = JSON.stringify({'query':
`query {
  getService(id: "1") {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    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": {
    "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"
    }
  }
}

Find service by code#

query {
  findService(code: "paypalplus") {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
  }
}
const body = JSON.stringify({'query':
`query {
  findService(code: "paypalplus") {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    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": {
    "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"
    }
  }
}

Search services#

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

query {
  searchServices(filter: "{\"=~\": {\"service.code\":\"demo-\"}}") {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    position
    status
    mtime
    ctime
    editor
  }
}
let filter = {
    "=~": {"service.code":"demo-"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
  searchServices(filter: ` + fstr + `) {
    id
    siteid
    type
    code
    label
    provider
    datestart
    dateend
    config
    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": {
    "searchServices": [
      {
        "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"
      },
      {
        "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"
      }
    ]
  }
}

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
  }
}
const body = JSON.stringify({'query':
`query {
  getServiceConfig(provider: "Xml,BasketValues", type: "delivery") {
    code
    type
    label
  }
}`});

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": {
    "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"
  }) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  saveService(input: {
    type: "delivery"
    code: "test"
    label: "Test service"
    provider: "Standard"
  }) {
    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": {
    "saveService": {
      "id": "13"
    }
  }
}

Save multiple services#

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

Delete single service#

mutation {
  deleteService(id: "13")
}
const body = JSON.stringify({'query':
`mutation {
  deleteService(id: "13")
}`});

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

Delete multiple services#

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

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": {
    "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.