type Shopify = {
token: string;
store_name: string;
};
/**
* Retrieve a list of products belonging to a collection
* Retrieve a list of products belonging to a collection. Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the page parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.. The products returned are sorted by the collection's sort order.
*/
export async function main(
auth: Shopify,
api_version: string = "2023-10",
collection_id: string,
limit: string | undefined
) {
const url = new URL(
`https://${auth.store_name}.myshopify.com/admin/api/${api_version}/collections/${collection_id}/products.json`
);
for (const [k, v] of [["limit", limit]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-Shopify-Access-Token": auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 109 days ago
type Shopify = {
token: string;
store_name: string;
};
/**
* Retrieve a list of products belonging to a collection
* Retrieve a list of products belonging to a collection. Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the page parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.. The products returned are sorted by the collection's sort order.
*/
export async function main(
auth: Shopify,
api_version: string = "2023-10",
collection_id: string,
limit: string | undefined
) {
const url = new URL(
`https://${auth.store_name}.myshopify.com/admin/api/${api_version}/collections/${collection_id}/products.json`
);
for (const [k, v] of [["limit", limit]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-Shopify-Access-Token": auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 655 days ago