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) 4 kB
import { BaseService } from '../infrastructure'; export class CustomCollections extends BaseService { constructor(shopDomain, accessToken) { super(shopDomain, accessToken, "custom_collections"); } /** * Get a count of all custom collections that contain a given product * @param options Options for filtering the results. * @see https://help.shopify.com/api/reference/customcollection#count */ count(options) { return this.createRequest("GET", "count.json", "count", options); } /** * Get a list of all custom collections that contain a given product * @param options Options for filtering the results. */ list(options) { return this.createRequest("GET", ".json", "custom_collections", options); } /** * Get a single custom collection * @param id The collection's id. * @param options Options for filtering the results. */ get(id, options) { return this.createRequest("GET", `${id}.json`, "custom_collection", options); } /** * Creates a custom collection. * @param collection The collection being created. * @param options Options for creating the collection. */ create(collection) { return this.createRequest("POST", ".json", "custom_collection", { custom_collection: collection }); } /** * Updates a custom collection with the given id. * @param id The collection's id. * @param collection The updated collection. */ update(id, collection) { return this.createRequest("PUT", `${id}.json`, "custom_collection", { custom_collection: collection }); } /** * Deletes a custom collection with the given id. * @param id The collection's id. */ delete(id) { return this.createRequest("DELETE", `${id}.json`); } /** * Gets a list of up to 250 metafields from the given customCollection. * @param id The customCollection's id. * @param options Options for filtering the results. */ listMetafields(customCollectionId, options) { return this.createRequest("GET", `${customCollectionId}/metafields.json`, 'metafields', options); } /** * Returns the number of metafields belonging to the given customCollection. * @param id The customCollection's id. */ countMetafields(customCollectionId) { return this.createRequest("GET", `${customCollectionId}/metafields/count.json`, 'count'); } /** * Gets the metafield with the given id from an customCollection. * @param customCollectionId The customCollection's id. * @param id The metafield's id. */ getMetafield(customCollectionId, id) { return this.createRequest("GET", `${customCollectionId}/metafields/${id}.json`, 'metafield'); } /** * Creates a metafield for the given customCollection. * @param customCollectionId The customCollection's id. * @param id The metafield's id. * @param metafield Options for the metafield */ createMetafield(customCollectionId, metafield) { return this.createRequest("POST", `${customCollectionId}/metafields.json`, 'metafield', { metafield }); } /** * Updates a metafield for the given customCollection * @param customCollectionId The customCollection's id. * @param id The metafield's id. * @param metafield Options for the metafield */ updateMetafield(customCollectionId, id, metafield) { return this.createRequest("PUT", `${customCollectionId}/metafields/${id}.json`, 'metafield', { metafield }); } /** * Deletes the metafield with the given id from an customCollection. * @param customCollectionId The customCollection's id. * @param id The metafield's id. */ deleteMetafield(customCollectionId, id) { return this.createRequest("DELETE", `${customCollectionId}/metafields/${id}.json`, 'metafield'); } } export default CustomCollections;