You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Admin API References, it is specified that the query parameter variants[q] can be passed in the API endpoint Admin List Products as shown in the following image.
I reviewed the code, and indeed the validator accepts this query parameter.
However, I get an error when passing this specific parameter.
error: Trying to query by not existing property ProductVariant.q
The reason I need this is because I want to filter products by their SKU or barcode, which are properties of product variants.
Steps to reproduce
Create a Medusa application using the command create-medusa-app.
Create a user.
Create a product with a variant that includes an SKU or barcode if there are no products.
Make a request to the Admin List Products Endpoint with the query parameter variants[q] or variants.q:
Note: If you want to filter by the variant ID with the query param variants[id] or variants.id, it works fine, as do other query parameters such as variants[manage_inventory] or variants[allow_backorder].
Expected behavior
You can filter products by passing the query parameter variants[q] to the endpoint Admin List Products and the response will only show products whose variants properties are searchable match the query parameter.
Actual behavior
You receive the following response with a 500 status code:
And the following error is displayed in the console:
error: Trying to query by not existing property ProductVariant.q
Error: Trying to query by not existing property ProductVariant.q
at /Users/dev/Documents/Dev/medusa-2.0/my-medusa-store/node_modules/@mikro-orm/knex/query/CriteriaNode.js:28:27
at Array.forEach (<anonymous>)
at new CriteriaNode (/Users/dev/Documents/Dev/medusa-2.0/my-medusa-store/node_modules/@mikro-orm/knex/query/CriteriaNode.js:23:17)
at new ScalarCriteriaNode (/Users/dev/Documents/Dev/medusa-2.0/my-medusa-store/node_modules/@mikro-orm/knex/query/ScalarCriteriaNode.js:9:1)
at Function.createScalarNode (/Users/dev/Documents/Dev/medusa-2.0/my-medusa-store/node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:25:22)
at Function.createNode (/Users/dev/Documents/Dev/medusa-2.0/my-medusa-store/node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:22:21)
at Function.createObjectItemNode (/Users/dev/Documents/Dev/medusa-2.0/my-medusa-store/node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:51:25)
at /Users/dev/Documents/Dev/medusa-2.0/my-medusa-store/node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:42:28
at Array.reduce (<anonymous>)
at Function.createObjectNode (/Users/dev/Documents/Dev/medusa-2.0/my-medusa-store/node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:41:45)
http: GET /admin/products?variants%5Bq%5D=test ← - (500) - 20.246 ms
Link to reproduction repo
Fresh install with create-medusa-app command
The text was updated successfully, but these errors were encountered:
Hi @WingNgCode,
the q is a query parameter, not a property from the entity, so you can use it like this: /admin/products?q=test /admin/products/[id]/variants?q=test
or if using the service directly, from methods like productModule.listProducts, the q is accepted on the where clause.
Hi @WingNgCode, the q is a query parameter, not a property from the entity, so you can use it like this: /admin/products?q=test/admin/products/[id]/variants?q=test
or if using the service directly, from methods like productModule.listProducts, the q is accepted on the where clause.
Thank you for your response @carlos-r-l-rodrigues. I suppose that if I want to filter products by SKU or barcode, I will need to consider another approach or create a custom endpoint, as the query parameter described in your API references cannot be used.
Package.json file
Node.js version
v21.7.1
Database and its version
PostgreSQL 17.2
Operating system name and version
MacOS Sequoia 15.1.1
Browser name
Chrome
What happended?
In the Admin API References, it is specified that the query parameter
variants[q]
can be passed in the API endpoint Admin List Products as shown in the following image.I reviewed the code, and indeed the validator accepts this query parameter.
However, I get an error when passing this specific parameter.
The reason I need this is because I want to filter products by their SKU or barcode, which are properties of product variants.
Steps to reproduce
create-medusa-app
.variants[q]
orvariants.q
:or
500
:Expected behavior
You can filter products by passing the query parameter
variants[q]
to the endpoint Admin List Products and the response will only show products whose variants properties are searchable match the query parameter.Actual behavior
You receive the following response with a 500 status code:
And the following error is displayed in the console:
Link to reproduction repo
Fresh install with create-medusa-app command
The text was updated successfully, but these errors were encountered: