//native
/**
* Search Products
* Search products with Shopify's search syntax (e.g. `title:*hoodie* vendor:Acme status:active tag:sale`, `sku:ABC-1`, `collection_id:123`). Leave query empty to list all products. Returns one page; pass pageInfo.endCursor as after for the next.
*/
export async function main(
auth: RT.Shopify,
query: string | undefined,
sort_key:
| "TITLE"
| "CREATED_AT"
| "UPDATED_AT"
| "PUBLISHED_AT"
| "PRODUCT_TYPE"
| "VENDOR"
| "INVENTORY_TOTAL"
| "ID"
| "RELEVANCE"
| undefined,
reverse: boolean | undefined,
first: number | undefined,
after: string | undefined
) {
const response = await fetch(
`https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
{
method: "POST",
headers: {
"X-Shopify-Access-Token": auth.token,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `query ($first: Int!, $after: String, $query: String, $sortKey: ProductSortKeys, $reverse: Boolean) { products(first: $first, after: $after, query: $query, sortKey: $sortKey, reverse: $reverse) { nodes { id legacyResourceId title handle status vendor productType tags createdAt updatedAt publishedAt totalInventory variantsCount { count } priceRangeV2 { minVariantPrice { amount currencyCode } maxVariantPrice { amount currencyCode } } featuredMedia { preview { image { url } } } } pageInfo { hasNextPage endCursor } } }`,
variables: {
first: first || 50,
after: after || undefined,
query: query || undefined,
sortKey: sort_key || undefined,
reverse: reverse || undefined,
},
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
return data.products
}
Submitted by hugo989 3 hours ago