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