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.

122 lines (121 loc) 4.18 kB
import { BaseService } from '../infrastructure'; export class Customers extends BaseService { constructor(shopDomain, accessToken) { super(shopDomain, accessToken, "customers"); } /** * Get a count of all customers */ count() { return this.createRequest("GET", "count.json", "count"); } /** * Get a list of all customers * @param options Options for filtering the results. */ list(options) { return this.createRequest("GET", ".json", "customers", options); } /** * Searches for customers that match a supplied query. * @param options Options for searching customers */ search(options) { return this.createRequest("GET", "search.json", "customers", options); } /** * Get a single customer * @param id The customer's id. * @param options Options for filtering the results. */ get(id, options) { return this.createRequest("GET", `${id}.json`, "customer", options); } /** * Creates a customer. * @param customer The customer being created. * @param options Options for creating the customer. */ create(customer) { return this.createRequest("POST", ".json", "customer", { customer: customer }); } /** * Updates a customer with the given id. * @param id The customer's id. * @param customer The updated customer. */ update(id, customer) { return this.createRequest("PUT", `${id}.json`, "customer", { customer: customer }); } /** * Deletes a customer with the given id. * @param id The customer's id. */ delete(id) { return this.createRequest("DELETE", `${id}.json`); } /** * Generate an account activation URL for a customer whose account is not yet enabled * @param id The customer's ids */ createActivationUrl(id) { return this.createRequest("POST", `${id}/account_activation_url.json`, "account_activation_url"); } /** * Sends an account invite to a customer. * @param invite Optional invitation to send */ invite(invite) { return this.createRequest("POST", "send_invite.json", "customer_invite", { customer_invite: invite }); } /** * Gets a list of up to 250 metafields from the given customer. * @param id The customer's id. * @param options Options for filtering the results. */ listMetafields(customerId, options) { return this.createRequest("GET", `${customerId}/metafields.json`, 'metafields', options); } /** * Returns the number of metafields belonging to the given customer. * @param id The customer's id. */ countMetafields(customerId) { return this.createRequest("GET", `${customerId}/metafields/count.json`, 'count'); } /** * Gets the metafield with the given id from an customer. * @param customerId The customer's id. * @param id The metafield's id. */ getMetafield(customerId, id) { return this.createRequest("GET", `${customerId}/metafields/${id}.json`, 'metafield'); } /** * Creates a metafield for the given customer. * @param customerId The customer's id. * @param id The metafield's id. * @param metafield Options for the metafield */ createMetafield(customerId, metafield) { return this.createRequest("POST", `${customerId}/metafields.json`, 'metafield', { metafield }); } /** * Updates a metafield for the given customer * @param customerId The customer's id. * @param id The metafield's id. * @param metafield Options for the metafield */ updateMetafield(customerId, id, metafield) { return this.createRequest("PUT", `${customerId}/metafields/${id}.json`, 'metafield', { metafield }); } /** * Deletes the metafield with the given id from an customer. * @param customerId The customer's id. * @param id The metafield's id. */ deleteMetafield(customerId, id) { return this.createRequest("DELETE", `${customerId}/metafields/${id}.json`, 'metafield'); } } export default Customers;