UNPKG

shopify-admin-api

Version:

Shopify Admin API is a NodeJS library built to help developers easily authenticate and make calls against the Shopify API. It was inspired by and borrows heavily from ShopifySharp.

103 lines (102 loc) 3.54 kB
import { BaseService } from '../infrastructure'; export class Products extends BaseService { constructor(shopDomain, accessToken) { super(shopDomain, accessToken, "products"); } /** * Gets a count of all of the shop's Products. * @param options Options for filtering the results. * @see https://help.shopify.com/api/reference/product#count */ count(options) { return this.createRequest("GET", "count.json", "count", options); } /** * Gets a list of up to 250 of the shop's Products. * @param options Options for filtering the results. */ list(options) { return this.createRequest("GET", ".json", "products", options); } /** * Gets the Product with the given id. * @param id The Product's id. * @param options Options for filtering the results. */ get(id, options) { return this.createRequest("GET", `${id}.json`, "product", options); } /** * Creates an Product. * @param product The Product being created. * @param options Options for creating the Product. */ create(product) { return this.createRequest("POST", ".json", "product", { product }); } /** * Updates an Product with the given id. * @param id The Product's id. * @param product The updated Product. */ update(id, product) { return this.createRequest("PUT", `${id}.json`, "product", { product }); } /** * Deletes an Product with the given id. * @param id The Product's id. */ delete(id) { return this.createRequest("DELETE", `${id}.json`); } /** * Gets a list of up to 250 metafields from the given product. * @param id The product's id. * @param options Options for filtering the results. */ listMetafields(productId, options) { return this.createRequest("GET", `${productId}/metafields.json`, 'metafields', options); } /** * Returns the number of metafields belonging to the given product. * @param id The product's id. */ countMetafields(productId) { return this.createRequest("GET", `${productId}/metafields/count.json`, 'count'); } /** * Gets the metafield with the given id from an product. * @param productId The product's id. * @param id The metafield's id. */ getMetafield(productId, id) { return this.createRequest("GET", `${productId}/metafields/${id}.json`, 'metafield'); } /** * Creates a metafield for the given product. * @param productId The product's id. * @param id The metafield's id. * @param metafield Options for the metafield */ createMetafield(productId, metafield) { return this.createRequest("POST", `${productId}/metafields.json`, 'metafield', { metafield }); } /** * Updates a metafield for the given product * @param productId The product's id. * @param id The metafield's id. * @param metafield Options for the metafield */ updateMetafield(productId, id, metafield) { return this.createRequest("PUT", `${productId}/metafields/${id}.json`, 'metafield', { metafield }); } /** * Deletes the metafield with the given id from an product. * @param productId The product's id. * @param id The metafield's id. */ deleteMetafield(productId, id) { return this.createRequest("DELETE", `${productId}/metafields/${id}.json`, 'metafield'); } } export default Products;