How to filter product text by API (jsonadm and graphql) request

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
ИванМаксимов
Posts: 8
Joined: 06 Sep 2023, 17:16

How to filter product text by API (jsonadm and graphql) request

Post by ИванМаксимов » 06 Sep 2023, 17:36

Please, help me write API request to get long english text for a given product. For graphql or jsonadm API.

I try graphql request (on default demo data):

Code: Select all

"query":"query { getProduct(id:\"15\", include: [\"product/text\"]){ id,type,label,lists{text(listtype: \"default\", type: \"long\") { id, item (languageid: \"en\") { type label languageid } } } }}"
But get error:

Code: Select all

"message":"Unknown argument \"languageid\" on field \"item\" of type \"productliststextOutput\".
I try for just check filtering text attrs feature :

Code: Select all

"query":"query { searchProducts( include: [\"product/text\"], filter: \"{\\\"==\\\":{\\\"product/text.type\\\":\\\"long\\\"}}\" ){ id,type,label,lists{text(listtype: \"default\", type: \"long\") { id, item { type label languageid } } } }}"
or product.text.type
But get error:

Code: Select all

{"errors":[{"message":"Internal server error","locations":[{"line":1,"column":9}],"path":["searchProducts"]}],"data":{"searchProducts":null}}
Env:
"aimeos/aimeos-laravel": 2023.07.01
"laravel/framework": v10.21.0
php 8.1
Docker
Mac

User avatar
aimeos
Administrator
Posts: 7895
Joined: 01 Jan 1970, 00:00

Re: How to filter product text by API (jsonadm and graphql) request

Post by aimeos » 06 Sep 2023, 17:49

This should work:

Code: Select all

query {
  searchProducts(filter: "{}", include: ["product/text"]) {
    id
    type
    code
    label
    lists {
      text(listtype: "default", type: "long") {
        id
        item {
          type
          domain
          languageid
          label
        }
      }
    }
  }
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ИванМаксимов
Posts: 8
Joined: 06 Sep 2023, 17:16

Re: How to filter product text by API (jsonadm and graphql) request

Post by ИванМаксимов » 06 Sep 2023, 18:02

This worked, but i ask about "english" text!
How to filter by languadeid field value?

User avatar
aimeos
Administrator
Posts: 7895
Joined: 01 Jan 1970, 00:00

Re: How to filter product text by API (jsonadm and graphql) request

Post by aimeos » 06 Sep 2023, 18:18

You can't. The GraphQL API is for administration purpose only and you can't limit the texts of the product by any property because you need to pass all texts when you save them again. Texts with are not sent in the request are deleted.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ИванМаксимов
Posts: 8
Joined: 06 Sep 2023, 17:16

Re: How to filter product text by API (jsonadm and graphql) request

Post by ИванМаксимов » 06 Sep 2023, 18:42

aimeos wrote: 06 Sep 2023, 18:18 You can't. The GraphQL API is for administration purpose only and you can't limit the texts of the product by any property because you need to pass all texts when you save them again. Texts with are not sent in the request are deleted.
Ok. What about jsonadm ? By jsonadm API it's possible?

User avatar
ИванМаксимов
Posts: 8
Joined: 06 Sep 2023, 17:16

Re: How to filter product text by API (jsonadm and graphql) request

Post by ИванМаксимов » 06 Sep 2023, 18:46

And the next question: how to update the content of one text for a product?
Pease, give example request of update one text of existing product

User avatar
aimeos
Administrator
Posts: 7895
Joined: 01 Jan 1970, 00:00

Re: How to filter product text by API (jsonadm and graphql) request

Post by aimeos » 07 Sep 2023, 08:24

The JsonAdm API allows updating single items but it's deprecated and you shouldn't use it any more because it will be removed in the future.

With the GraphQL API, you can update all (text) items at once (pass those you didn't modify too, otherwise the will be deleted):

Code: Select all

mutation {
  saveProduct(input: {
    id: "123",
    code: "test"
    label: "Test product"
    lists: {
      text: [{
        type: "default",
        item: {
          content: "...",
          label: "...",
      	  languageid: "..."
        }, {
          // ...
        }
      ] 
    }
  }) {
    id
  }
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
ИванМаксимов
Posts: 8
Joined: 06 Sep 2023, 17:16

Re: How to filter product text by API (jsonadm and graphql) request

Post by ИванМаксимов » 07 Sep 2023, 09:35

Thank you so much!
aimeos wrote: 07 Sep 2023, 08:24

Code: Select all

mutation {
  saveProduct(input: {
    id: "123",
    code: "test"
    label: "Test product"
    lists: {
      text: [{
        type: "default",
type: "default" <--- is it a list entry type? where can I find out what types are available and what they are for?

User avatar
aimeos
Administrator
Posts: 7895
Joined: 01 Jan 1970, 00:00

Re: How to filter product text by API (jsonadm and graphql) request

Post by aimeos » 08 Sep 2023, 07:03

ИванМаксимов wrote: 07 Sep 2023, 09:35 type: "default" <--- is it a list entry type? where can I find out what types are available and what they are for?
Have a look into the "Types > Product lists" panel in admin backend. There you can see the available types and can add your own. They can be used in the frontend for additional grouping of referenced items but for texts, their value is almost always "default" (which you can skip because it's also the default value).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply