npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shopifapi

v0.3.2

Published

a thin wrapper for the shopify api

Downloads

29

Readme

shopifapi

A thin wrapper around the Shopify API for node.js. Shopifapi currently only supports basic authentication connections to the Shopify API.

Note that shopifapi implements a burst-queue to prevent hitting the Shopify API call limit. This means that calls on a shopifapi object may call back immediately or may call back in many minutes, depending on the frequency of Shopify API calls.

Install

npm install shopifapi

Example

var Shopifapi = require('shopifapi');
var shopify = new Shopifapi({
    auth: {
        username: 'somereallylongauthkey',
        password: 'somereallylongpassword'
    },
    url: 'https://mywebsite.myshopify.com'
});

shopify.create.product({
  "title": "Burton Custom Freestlye 151",
  "body_html": "<strong>Good snowboard!</strong>",
  "vendor": "Burton",
  "product_type": "Snowboard",
  "variants": [
    {
      "option1": "First",
      "price": "10.00",
      "sku": 123
    },
    {
      "option1": "Second",
      "price": "20.00",
      "sku": "123"
    }
  ]
}, function(err, result) {
  // ... result is product with id 1 and variants with ids 2 and 3
});

shopify.get.product.withId(1, function(err, result) {
  console.log(result);
  // { id: 1, title: "Burton Custom Freestlye 151", ... }
});

shopify.get.product.variant.withId([1, 2], function(err, result) {
  console.log(result);
  // { option1: "First", "price": "10.00", ... }
});

shopify.update.product(1, { tags: "snowboard" }, function(err, result) {
  // Updated product response
});

shopify.get.products.list({ limit: 10, collection_id: 789 }, function(err, result) {
  console.log(result);
  // [ product1, product2, product3, ..., product10 ]
});

Constructor Options

auth

The auth object takes two items:

  • username: A shopify dev key
  • password: A shopify dev password

url

This is the url of the shopify store to connect to.

Example

var Shopifapi = require('shopifapi');
var shopify = new Shopifapi({
    auth: {
        username: 'somereallylongauthkey',
        password: 'somereallylongpassword'
    },
    url: 'https://mywebsite.myshopify.com'
});

Objects

Shopify objects can be referred to in either the singular or plural form. Whichever word you use will not impact the underlying shopify api call. In other words, using shopify.get.product.list() is the same as calling shopify.get.products.list(). The ability to use singular or plural is just syntactic sugar.

Supported Shopify Objects

  • blogs
  • checkout(s)
  • collects
  • comment(s)
  • countries
  • customCollection(s)
  • customer(s)
  • order(s)
  • page(s)
  • product(s)
  • shop
  • smartCollection(s)
  • variant(s)

Example

var Shopifapi = require('shopifapi');
var shopify = new Shopifapi({ /* options here */ });

shopify.get.product.list(function(err, products) {
  console.log(products);
  // [ p1, p2, ..., pn ]
});

shopify.get.products.list(function(err, products) {
  console.log(products);
  // [ p1, p2, ..., pn ]
});

Subobjects

Shopify subobjects can also be referred to in either the singular or plural form without affecting the underlying api call. Subobjects need to be called following a shopify object.

Supported Shopify Subobjects Objects

  • product(s).image(s)
  • product(s).variant(s)
  • order(s).transaction(s)

Example

var Shopifapi = require('shopifapi');
var shopify = new Shopifapi({ /* options here */ });

// 123 is the product id to get variants for
shopify.get.product.variants.list(123, function(err, variants) {
  console.log(variants);
  // [v1, v2, ..., vn ]
});

// 123 is the product id and 456 is the image id
shopify.get.product.image.withId([123, 456], function(err, image) {
  console.log(image);
  // { id: 456, product_id: 123, ... }
});

Methods

get.object.withId(id, callback)

Get a shopify object (product, customCollection, etc) with id passed in as a Number.

Example

shopify.get.product.withId(123, function(err, product) {
  console.log(product);
  // { id: 123, ... }
});

get.object.subobject.withId([object_id, subobject_id], callback)

Get a shopify subobject (variant, image) with an array of ids. The order of the array is important and requires the object id to come before the subobject id.

Example

shopify.get.product.variant.withId([123, 678], function(err, variant) {
  console.log(variant);
  // { id: 678, product_id: 123, ... }
});

get.object.count([options], callback)

Get the total count of a shopify object type like product or smartCollection. You can provide options in the form of an Object. The options argument can be given parameters to constrain the resulting list. For example, you could provide a collection_id to list all products from a specific collection. A more detailed list of available shopify parameters can be found in the Shopify API Documentation in the Endpoints section.

Example

shopify.get.products.count(function(err, response) {
  console.log(response);
  // 94
});

// or

shopify.get.products.count({ collection_id: 9 }, function(err, response) {
  console.log(response);
  // 23
});

get.object.subobject.count(id, callback)

Get the total count of a shopify subobject type like product.variant or product.image.

Example

// Get the count of variants for product with id 123
shopify.get.product.variants.count(123, function(err, response) {
  console.log(response);
  // 4
});

get.object.list([options], callback)

Get a list of shopify objects. You can provide options in the form of an Object. The options argument can be given parameters to constrain the resulting list. For example, you could provide a collection_id to list all products from a specific collection. A more detailed list of available shopify parameters can be found in the Shopify API Documentation in the Endpoints section.

Example

shopify.get.products.list({collection_id: 9, limit: 10}, function(err, products) {
  console.log(products);
  // [p1, p2, ..., p10]
});

get.object.subobject.list(id, [options], callback)

Get a list of shopify subobjects like product.variants and product.images. You can provide options in the form of an Object. The options argument can be given parameters to constrain the resulting list. For example, you could provide a limit to cap the number of variants to return. A more detailed list of available shopify parameters can be found in the Shopify API Documentation in the Endpoints section.

Example

shopify.get.product.variants.list(123, {limit: 3}, function(err, products) {
  console.log(products);
  // [v1, v2, v3]
});

update.object(id, options, callback)

Update a shopify object. The id is the id of the object to update. The options contains updated properties of the object.

Example

shopify.update.product(123, {title: 'New and Improved Product123'}, function(err, product) {
  console.log(product);
  // { /* udpated product data */ }
});

create.object(options, callback) {

Create a shopify object. The options is an Object that contains the new shopify object's information.

Example

shopify.create.product({
  title: "Super Snowboard Freestlye 151",
  body_html: "<strong>Good snowboard!</strong>",
  vendor: "SuperDuper",
  product_type: "Snowboard",
  variants: [
    {
      option1: "First",
      price: "10.00",
      sku: 123
    },
    {
      option1: "Second",
      price: "20.00",
      sku: 124
    }
  ]
}, function(err, product) {
  console.log(product);
  // { /* new product data */ }
});

remove.object(id, callback) {

Remove a shopify object. The id is a Number that is the id of the shopify object you want to delete.

Example

shopify.remove.product(123, function(err, product) {
  console.log(product);
  // {}
});

queue()

Returns the number of API calls enqueued. Since requests are throttled to stay under the shopify api call limits, this can be useful to know how many requests are pending.

var requestsRemaining = shopify.queue();
console.log(requestsRemaining);
// 32

The MIT License

Copyright (c) 2014 Michael Maelzer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.