A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello
I Need to there is any option that we can pass product's into REST API product api that we did not want that products id's in "admin/api/2022-04/products.json" in this api e.g
We did not want product id 75825896,48589658,4785996 that we can pass these ids into "admin/api/2022-04/products.json" api and did not return these product's ids information
Hi @vinodk
Here's a link to the documentation on the supported filter parameters for the REST Admin API's products.json endpoint.
There is no option to exclude, or filter by id with REST, but the GraphQL Admin API's products query parameter takes a string, which offers much more flexibility by leveraging the Shopify search syntax.
I was able to filter products by ID on my test store using a query like this:
query excludeFilter {
products(
first: 10
query: "NOT id:'7215955836950' AND NOT id:'7215955804182' AND NOT id'7216003186710"
) {
edges {
node {
id
title
}
}
}
}
Hope that helps.
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi team,
I have a similar case, but I want those Ids to be a list of ids to be excluded, and this list of ids to be passed as a variable. Could please advise if that available ? I tried your above query converted to a hard coded list and it doesn't work like that
Hi @Mariam_13,
While you can pass a variable for the filter query, at this time it does not accept lists of ids in an array or other data structure as it's input. The input for the query filter must be a string as described above.
However as you can pass the string through a variable, you should be able to programatically construct the strings to include the ids you wish, with your apps logic, before making the API call.
While we can't help exactly with coding your app to programatically generate the strings to pass, we can provide you with an example of what passing an already generated string will look like in GraphQL.
Query Body:
query excludeFilter ($excludeString: String!){
products(
first: 10
query: $excludeString
) {
edges {
node {
id
title
}
}
}
}
Query Variables:
{
"excludeString": "NOT id:'7215955836950' AND NOT id:'7215955804182' AND NOT id'7216003186710"
}
I hope this helps, and I hope you have a great day 🙂
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog