Skip to content

Products

This article contains all actions for retrieving and managing products.

Tip

The product domain supports fetching related resources.

Get product by ID#

query {
  getProduct(id: "1", include: ["text"]) {
    id
    siteid
    type
    code
    label
    url
    dataset
    datestart
    dateend
    config
    instock
    scale
    status
    target
    boost
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
    property {
      id
      type
      languageid
      value
    }
  }
}
Aimeos.query(`query {
  getProduct(id: "1", include: ["text"]) {
    id
    siteid
    type
    code
    label
    url
    dataset
    datestart
    dateend
    config
    instock
    scale
    status
    target
    boost
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
    property {
      id
      type
      languageid
      value
    }
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`query {
  getProduct(id: "1", include: ["text"]) {
    id
    siteid
    type
    code
    label
    url
    dataset
    datestart
    dateend
    config
    instock
    target
    scale
    status
    boost
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
    property {
      id
      type
      languageid
      value
    }
  }
}`});

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": {
    "getProduct": {
      "id": "113",
      "siteid": "1.",
      "type": "default",
      "code": "demo-article",
      "label": "Demo article",
      "url": "demo-article",
      "dataset": null,
      "datestart": null,
      "dateend": null,
      "config": "{}",
      "instock": null,
      "target": null,
      "scale": 1,
      "status": 1,
      "boost": 1,
      "mtime": "2023-01-13 11:25:51",
      "ctime": "2022-12-01 11:59:00",
      "editor": "aimeos@aimeos.org",
      "lists": {
        "text": [{
          "id": "1",
          "item": {
            "id": "10",
            "content": "Test content"
          }
        }]
      },
      "property": [{
        "id": "1",
        "type": "isbn",
        "languageid": null,
        "value": "12345678"
      }]
    }
  }
}

Find product by code#

query {
  findProduct(code: "demo-article", include: ["text"]) {
    id
    siteid
    type
    code
    label
    url
    dataset
    datestart
    dateend
    config
    instock
    scale
    status
    target
    boost
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
    property {
      id
      type
      languageid
      value
    }
  }
}
Aimeos.query(`query {
  findProduct(code: "demo-article", include: ["text"]) {
    id
    siteid
    type
    code
    label
    url
    dataset
    datestart
    dateend
    config
    instock
    scale
    status
    target
    boost
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
    property {
      id
      type
      languageid
      value
    }
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`query {
  findProduct(code: "demo-article", include: ["text"]) {
    id
    siteid
    type
    code
    label
    url
    dataset
    datestart
    dateend
    config
    instock
    scale
    status
    target
    boost
    mtime
    ctime
    editor
    lists {
      text {
        id
        item {
          id
          content
        }
      }
    }
    property {
      id
      type
      languageid
      value
    }
  }
}`});

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": {
    "findProduct": {
      "id": "1",
      "siteid": "1.",
      "type": "default",
      "code": "demo-article",
      "label": "Demo article",
      "url": "demo-article",
      "dataset": null,
      "datestart": null,
      "dateend": null,
      "config": "{}",
      "instock": null,
      "scale": 1,
      "status": 1,
      "target": null,
      "boost": 1,
      "mtime": "2023-01-13 11:25:51",
      "ctime": "2022-12-01 11:59:00",
      "editor": "aimeos@aimeos.org",
      "lists": {
        "text": [{
          "id": "1",
          "item": {
            "id": "10",
            "content": "Test content"
          }
        }]
      },
      "property": [{
        "id": "1",
        "type": "isbn",
        "languageid": null,
        "value": "12345678"
      }]
    }
  }
}

Search products#

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

query {
  searchProducts(filter: "{\\"=~\\": {\\"product.code\\":\\"demo-\\"}}", include: ["text"]) {
    items {
      id
      siteid
      type
      code
      label
      url
      dataset
      datestart
      dateend
      config
      instock
      scale
      status
      target
      boost
      mtime
      ctime
      editor
      lists {
        text {
          id
          item {
            id
            content
          }
        }
      }
      property {
        id
        type
        languageid
        value
      }
    }
    total
  }
}
Aimeos.query(`query {
  searchProducts(filter: "{\\"=~\\": {\\"product.code\\":\\"demo-\\"}}", include: ["text"]) {
    items {
      id
      siteid
      type
      code
      label
      url
      dataset
      datestart
      dateend
      config
      instock
      scale
      status
      target
      boost
      mtime
      ctime
      editor
      lists {
        text {
          id
          item {
            id
            content
          }
        }
      }
      property {
        id
        type
        languageid
        value
      }
    }
    total
  }
}`).then(data => {
  console.log(data)
})
let filter = {
    "=~": {"product.code":"demo-"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
  searchProducts(filter: ` + fstr + `, include: ["text"]) {
    items {
      id
      siteid
      type
      code
      label
      url
      dataset
      datestart
      dateend
      config
      instock
      scale
      status
      target
      boost
      mtime
      ctime
      editor
      lists {
        text {
          id
          item {
            id
            content
          }
        }
      }
      property {
        id
        type
        languageid
        value
      }
    }
    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": {
    "searchProducts": {
      "items": [
        {
          "id": "1",
          "siteid": "1.",
          "type": "default",
          "code": "demo-article",
          "label": "Demo article",
          "url": "demo-article",
          "dataset": null,
          "datestart": null,
          "dateend": null,
          "config": "{}",
          "instock": null,
          "scale": 1,
          "status": 1,
          "target": null,
          "boost": 1,
          "mtime": "2023-01-13 11:25:51",
          "ctime": "2022-12-01 11:59:00",
          "editor": "aimeos@aimeos.org",
          "lists": {
            "text": [{
              "id": "1",
              "item": {
                "id": "10",
                "content": "Test content"
              }
            }]
          },
          "property": [{
            "id": "1",
            "type": "isbn",
            "languageid": null,
            "value": "12345678"
          }]
        },
        {
          "id": "2",
          "siteid": "1.",
          "type": "default",
          "code": "demo-selection-article-1",
          "label": "Demo variant article 1",
          "url": "demo-variant-article-1",
          "dataset": null,
          "datestart": null,
          "dateend": null,
          "config": "{}",
          "instock": null,
          "scale": 1,
          "status": 1,
          "target": null,
          "boost": 1,
          "mtime": "2022-12-01 11:59:05",
          "ctime": "2022-12-01 11:59:05",
          "editor": "core",
          "lists": {
            "text": []
          },
          "property": []
        }
      ],
      "total": 2
    }
  }
}

Save single product#

mutation {
  saveProduct(input: {
    code: "test"
    label: "Test product",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    },
    property: [{
      type: "isbn",
      languageid: null,
      value: "12345678"
    }]
  }) {
    id
  }
}
Aimeos.query(`mutation {
  saveProduct(input: {
    code: "test"
    label: "Test product",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    },
    property: [{
      type: "isbn",
      languageid: null,
      value: "12345678"
    }]
  }) {
    id
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
  saveProduct(input: {
    code: "test"
    label: "Test product",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    },
    property: [{
      type: "isbn",
      languageid: null,
      value: "12345678"
    }]
  }) {
    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": {
    "saveProduct": {
      "id": "18"
    }
  }
}

Save multiple products#

mutation {
  saveProducts(input: [{
    code: "test-2"
    label: "Test 2 product",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    },
    property: [{
      type: "isbn",
      languageid: null,
      value: "12345678"
    }]
  },{
    code: "test-3"
    label: "Test 3 product"
  }]) {
    id
  }
}
Aimeos.query(`mutation {
  saveProducts(input: [{
    code: "test-2"
    label: "Test 2 product",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    },
    property: [{
      type: "isbn",
      languageid: null,
      value: "12345678"
    }]
  },{
    code: "test-3"
    label: "Test 3 product"
  }]) {
    id
  }
}`).then(data => {
  console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
  saveProducts(input: [{
    code: "test-2"
    label: "Test 2 product",
    lists: {
      text: [{
        item: {
          content: "Test content"
        }
      }]
    },
    property: [{
      type: "isbn",
      languageid: null,
      value: "12345678"
    }]
  },{
    code: "test-3"
    label: "Test 3 product"
  }]) {
    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": {
    "saveProducts": [
      {
        "id": "19"
      },
      {
        "id": "20"
      }
    ]
  }
}

Delete single product#

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

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": {
    "deleteProduct": "18"
  }
}

Delete multiple products#

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

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": {
    "deleteProducts": [
      "19",
      "20"
    ]
  }
}

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.