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.35 kB
JavaScript
import { BaseService } from '../infrastructure';
/**
* A service for manipulating a Shopify shop's blogs. For manipulating a blog's posts, use the Articles class instead.
*/
export class Blogs extends BaseService {
constructor(shopDomain, accessToken) {
super(shopDomain, accessToken, "blogs");
}
/**
* Creates a new blog.
* @param blog The Blog being created.
*/
create(blog) {
return this.createRequest("POST", `.json`, "blog", { blog });
}
/**
* Gets a blog with the given id.
* @param id Id of the blog to retrieve.
* @param options Options for filtering the result.
*/
get(id, options) {
return this.createRequest("GET", `${id}.json`, "blog", options);
}
/**
* Updates the blog with the given id.
* @param id Id of the blog being updated.
* @param blog The updated blog.
*/
update(id, blog) {
return this.createRequest("PUT", `${id}.json`, "blog", { blog });
}
/**
* Gets a list of all blogs on the shop.
* @param options Options for filtering the results.
*/
list(options) {
return this.createRequest("GET", `.json`, "blogs", options);
}
/**
* Gets a count of all blogs on the shop.
*/
count(options) {
return this.createRequest("GET", "count.json", "count");
}
/**
* Deletes the blog with the given id.
* @param id Id of the blog being deleted.
*/
delete(id) {
return this.createRequest("DELETE", `${id}.json`);
}
/**
* Gets a list of up to 250 metafields from the given blog.
* @param id The blog's id.
* @param options Options for filtering the results.
*/
listMetafields(blogId, options) {
return this.createRequest("GET", `${blogId}/metafields.json`, 'metafields', options);
}
/**
* Returns the number of metafields belonging to the given blog.
* @param id The blog's id.
*/
countMetafields(blogId) {
return this.createRequest("GET", `${blogId}/metafields/count.json`, 'count');
}
/**
* Gets the metafield with the given id from an blog.
* @param blogId The blog's id.
* @param id The metafield's id.
*/
getMetafield(blogId, id) {
return this.createRequest("GET", `${blogId}/metafields/${id}.json`, 'metafield');
}
/**
* Creates a metafield for the given blog.
* @param blogId The blog's id.
* @param id The metafield's id.
* @param metafield Options for the metafield
*/
createMetafield(blogId, metafield) {
return this.createRequest("POST", `${blogId}/metafields.json`, 'metafield', { metafield });
}
/**
* Updates a metafield for the given blog
* @param blogId The blog's id.
* @param id The metafield's id.
* @param metafield Options for the metafield
*/
updateMetafield(blogId, id, metafield) {
return this.createRequest("PUT", `${blogId}/metafields/${id}.json`, 'metafield', { metafield });
}
/**
* Deletes the metafield with the given id from an blog.
* @param blogId The blog's id.
* @param id The metafield's id.
*/
deleteMetafield(blogId, id) {
return this.createRequest("DELETE", `${blogId}/metafields/${id}.json`, 'metafield');
}
}
export default Blogs;