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.

58 lines (57 loc) 2.09 kB
import { BaseService } from '../infrastructure'; /** * A service for manipulating a blog's product variants. */ export class ProductVariants extends BaseService { constructor(shopDomain, accessToken) { super(shopDomain, accessToken, ""); } /** * Gets a variant with the given id. * @param id Id of the variant being retrieved. * @param options Options for filtering the result. */ get(id, options) { return this.createRequest("GET", `variants/${id}.json`, "variant", options); } /** * Lists up to 250 variants for the given product. * @param productId Id of the product that the variants belong to. * @param options Options for filtering the results. */ list(productId, options) { return this.createRequest("GET", `products/${productId}/variants.json`, "variants", options); } /** * Counts the variants on the given product. * @param productId Id of the product that the variants belong to. */ count(productId) { return this.createRequest("GET", `products/${productId}/variants/count.json`, "count"); } /** * Creates a new product variant * @param productId Id of the product that the varaint belongs to. * @param productVariant The updated variant. */ create(productId, variant) { return this.createRequest("POST", `variants/${productId}/variants.json`, "variant", { variant }); } /** * Updates an variant with the given id. * @param id Id of the variant. * @param productVariant The updated variant. */ update(id, variant) { return this.createRequest("PUT", `variants/${id}.json`, "variant", { variant }); } /** * Deletes the variant with the given variantId. * @param productId Id of the product that the varaint belongs to. * @param variantId Id of the variant to delete. */ delete(productId, variantId) { return this.createRequest("DELETE", `products/${productId}/variants/${variantId}.json`); } } export default ProductVariants;