type Shopify = {
token: string;
store_name: string;
};
/**
* Creates a new product
* Creates a new product. If you want to set the product's SEO information, then you can use the following properties: metafields_global_title_tag: The name of the product used for SEO purposes. Generally added to the <meta name='title'> tag. metafields_global_description_tag: A description of the product used for SEO purposes. Generally added to the <meta name='description'> tag.
*/
export async function main(
auth: Shopify,
api_version: string = "2023-10",
body: {
product?: {
body_html?: string;
product_type?: string;
published?: boolean;
title?: string;
vendor?: string;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://${auth.store_name}.myshopify.com/admin/api/${api_version}/products.json`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Shopify-Access-Token": auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 337 days ago
type Shopify = {
token: string;
store_name: string;
};
/**
* Creates a new product
* Creates a new product. If you want to set the product's SEO information, then you can use the following properties: metafields_global_title_tag: The name of the product used for SEO purposes. Generally added to the <meta name='title'> tag. metafields_global_description_tag: A description of the product used for SEO purposes. Generally added to the <meta name='description'> tag.
*/
export async function main(
auth: Shopify,
api_version: string = "2023-10",
body: {
product?: {
body_html?: string;
product_type?: string;
published?: boolean;
title?: string;
vendor?: string;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://${auth.store_name}.myshopify.com/admin/api/${api_version}/products.json`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Shopify-Access-Token": auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 883 days ago