Skip to content

Customers

This article contains all actions for retrieving and managing customers.

Tip

The customer domain supports fetching related resources.

Get customer by ID#

query {
  getCustomer(id: "1") {
    id
    siteid
    code
    label
    salutation
    company
    vatid
    title
    firstname
    lastname
    address1
    address2
    address3
    postal
    city
    state
    languageid
    countryid
    telephone
    email
    telefax
    website
    longitude
    status
    latitude
    birthday
    status
    dateverified
    password
    mtime
    ctime
    editor
  }
}
const body = JSON.stringify({'query':
`query {
  getCustomer(id: "1") {
    id
    siteid
    code
    label
    salutation
    company
    vatid
    title
    firstname
    lastname
    address1
    address2
    address3
    postal
    city
    state
    languageid
    countryid
    telephone
    email
    telefax
    website
    longitude
    status
    latitude
    birthday
    status
    dateverified
    password
    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": {
    "getCustomer": {
      "id": "1",
      "siteid": "1.",
      "code": "demo@example.com",
      "label": "Test user",
      "salutation": "mr",
      "company": "Test company",
      "vatid": "DE999999999",
      "title": null,
      "firstname": "Test",
      "lastname": "User",
      "address1": "Test street",
      "address2": "1",
      "address3": null,
      "postal": "10000",
      "city": "Test city",
      "state": "CA",
      "languageid": "en",
      "countryid": "US",
      "telephone": null,
      "email": "demo@example.com",
      "telefax": null,
      "website": null,
      "longitude": null,
      "status": 1,
      "latitude": null,
      "birthday": "2000-01-01",
      "dateverified": null,
      "password": "$2y$10$cdjdim/ITpPnf8H06i5wMOvlo6l3Slsz6E39sX6gZSpOIfIBD6W66",
      "mtime": "2022-12-01 11:59:04",
      "ctime": "2022-12-01 11:59:04",
      "editor": "core"
    }
  }
}

Find customer by code#

query {
  findCustomer(code: "test@example.com") {
    id
    siteid
    code
    label
    salutation
    company
    vatid
    title
    firstname
    lastname
    address1
    address2
    address3
    postal
    city
    state
    languageid
    countryid
    telephone
    email
    telefax
    website
    longitude
    status
    latitude
    birthday
    status
    dateverified
    password
    mtime
    ctime
    editor
  }
}
const body = JSON.stringify({'query':
`query {
  findCustomer(code: "test@example.com") {
    id
    siteid
    code
    label
    salutation
    company
    vatid
    title
    firstname
    lastname
    address1
    address2
    address3
    postal
    city
    state
    languageid
    countryid
    telephone
    email
    telefax
    website
    longitude
    status
    latitude
    birthday
    status
    dateverified
    password
    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": {
    "findCustomer": {
      "id": "1",
      "siteid": "1.",
      "code": "demo@example.com",
      "label": "Test user",
      "salutation": "mr",
      "company": "Test company",
      "vatid": "DE999999999",
      "title": null,
      "firstname": "Test",
      "lastname": "User",
      "address1": "Test street",
      "address2": "1",
      "address3": null,
      "postal": "10000",
      "city": "Test city",
      "state": "CA",
      "languageid": "en",
      "countryid": "US",
      "telephone": null,
      "email": "demo@example.com",
      "telefax": null,
      "website": null,
      "longitude": null,
      "status": 1,
      "latitude": null,
      "birthday": "2000-01-01",
      "dateverified": null,
      "password": "$2y$10$cdjdim/ITpPnf8H06i5wMOvlo6l3Slsz6E39sX6gZSpOIfIBD6W66",
      "mtime": "2022-12-01 11:59:04",
      "ctime": "2022-12-01 11:59:04",
      "editor": "core"
    }
  }
}

Search customers#

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

query {
  searchCustomers(filter: "{\"=~\": {\"customer.code\":\"demo-\"}}") {
    id
    siteid
    code
    label
    salutation
    company
    vatid
    title
    firstname
    lastname
    address1
    address2
    address3
    postal
    city
    state
    languageid
    countryid
    telephone
    email
    telefax
    website
    longitude
    status
    latitude
    birthday
    status
    dateverified
    password
    mtime
    ctime
    editor
  }
}
let filter = {
    "=~": {"customer.code":"demo-"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
  searchCustomers(filter: ` + fstr + `) {
    id
    siteid
    code
    label
    salutation
    company
    vatid
    title
    firstname
    lastname
    address1
    address2
    address3
    postal
    city
    state
    languageid
    countryid
    telephone
    email
    telefax
    website
    longitude
    status
    latitude
    birthday
    status
    dateverified
    password
    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": {
    "searchCustomers": [
      {
        "id": "1",
        "siteid": "1.",
        "code": "demo@example.com",
        "label": "Test user",
        "salutation": "mr",
        "company": "Test company",
        "vatid": "DE999999999",
        "title": null,
        "firstname": "Test",
        "lastname": "User",
        "address1": "Test street",
        "address2": "1",
        "address3": null,
        "postal": "10000",
        "city": "Test city",
        "state": "CA",
        "languageid": "en",
        "countryid": "US",
        "telephone": null,
        "email": "demo@example.com",
        "telefax": null,
        "website": null,
        "longitude": null,
        "status": 1,
        "latitude": null,
        "birthday": "2000-01-01",
        "dateverified": null,
        "password": "$2y$10$cdjdim/ITpPnf8H06i5wMOvlo6l3Slsz6E39sX6gZSpOIfIBD6W66",
        "mtime": "2022-12-01 11:59:04",
        "ctime": "2022-12-01 11:59:04",
        "editor": "core"
      }
    ]
  }
}

Save single customer#

mutation {
  saveCustomer(input: {
    code: "test-2@example.com"
    label: "Test 2 customer"
    city: "Test city"
    languageid: "en"
  }) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  saveCustomer(input: {
    code: "test-3@example.com"
    label: "Test customer"
    city: "Test city"
    languageid: "en"
  }) {
    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": {
    "saveCustomer": {
      "id": "3"
    }
  }
}

Save multiple customers#

mutation {
  saveCustomers(input: [{
    code: "test-3@example.com"
    label: "Test 3 customer"
    city: "Test city"
    languageid: "en"
  },{
    code: "test-4@example.com"
    label: "Test 4 customer"
    city: "Test city"
    languageid: "en"
  }]) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  saveCustomers(input: [{
    code: "test-3@example.com"
    label: "Test 3 customer"
    city: "Test city"
    languageid: "en"
  },{
    code: "test-4@example.com"
    label: "Test 4 customer"
    city: "Test city"
    languageid: "en"
  }]) {
    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": {
    "saveCustomers": [
      {
        "id": "4"
      },
      {
        "id": "5"
      }
    ]
  }
}

Delete single customer#

mutation {
  deleteCustomer(id: "3")
}
const body = JSON.stringify({'query':
`mutation {
  deleteCustomer(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": {
    "deleteCustomer": "3"
  }
}

Delete multiple customers#

mutation {
  deleteCustomers(id: ["4", "5"])
}
const body = JSON.stringify({'query':
`mutation {
  deleteCustomers(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": {
    "deleteCustomers": [
      "4",
      "5"
    ]
  }
}

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.