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

shopify-sdk

v2.2.4

Published

Shopify admin api

Downloads

11

Readme

Shopify SDK (Official Module)

Official Shopify admin API for web

Installation:

With Yarn:

$ yarn add shopify-sdk

With NPM:

$ npm install --save shopify-sdk

API

This module exports a buildConfig function which takes an options object.

Shopify.buildConfig(options)

Which creates a new Shopify instance.

Arguments

  • options - Required - A plain JavaScript object that contains the configuration options.

Options

  • shopName - Required - A string that specifies the shop name. The shop's "myshopify.com" domain is also accepted.
  • apiKey - Required for private apps - A string that specifies the API key of the app. This option must be used in conjunction with the password option and is mutually exclusive with the accessToken option.
  • password - Required for private apps - A string that specifies the private app password. This option must be used in conjunction with the apiKey option and is mutually exclusive with the accessToken option.
  • accessToken - Required for public apps - A string representing the permanent OAuth 2.0 access token. This option is mutually exclusive with the apiKey and password options. If you are looking for a premade solution to obtain an access token, take a look at the [shopify-token][] module.

Return value

A Shopify instance.

Example

import { Shopify } from "shopify-sdk";

const shopify = Shopify.buildConfig({
  shopName: 'your-shop-name',
  apiKey: 'your-api-key',
  password: 'your-app-password'
});

Resources

Every resource is accessed via your shopify instance:

const shopify = Shopify.buildConfig({
  shopName: 'your-shop-name',
  accessToken: 'your-oauth-token'
});

// shopify.<resource_name>().<method_name>

Each method returns a Promise that resolves with the result:

shopify.product().get()
  .then(products => console.log(products))
  .catch(err => console.error(err));

The Shopify API requires that you send a valid JSON string in the request body including the name of the resource. For example, the request body to create a country should be:

{
  "country": {
    "code": "FR",
    "tax": 0.25
  }
}

Other Examples

shopify.balance().get().then(balance => {
  console.log(balance);
});
shopify.dispute().get().then(disputes => {
  console.log(disputes);
});
shopify.dispute(123456).get().then(dispute => {
  console.log(dispute);
});
shopify.transaction().get().then(transactions => {
  console.log(transactions);
});
shopify.accessScope().get().then(accessScope => {
  console.log(accessScope);
});
shopify.storefrontAccessToken().get().then(accessTokens => {
  console.log(accessTokens);
});
shopify.storefrontAccessToken(755357713).get().then(accessToken => {
  console.log(accessToken);
});
shopify.report().get().then(reports => {
  console.log(reports);
});
shopify.report(682357713).get().then(report => {
  console.log(report);
});
shopify.applicationCharge().get().then(applicationCharges => {
  console.log(applicationCharges);
});
shopify.applicationCharge(45467871).get().then(applicationCharge => {
  console.log(applicationCharge);
});
shopify.applicationCharge(45467871).activate().post().then(applicationChargeActivate => {
  console.log(applicationChargeActivate);
});
shopify.applicationCredit().updateOrCreate({...}).post().then(applicationCredit => {
  console.log(applicationCredit);
});
shopify.applicationCredit().get().then(applicationCredits => {
  console.log(applicationCredits);
});
shopify.applicationCredit(79463336).get().then(applicationCredit => {
  console.log(applicationCredit);
});
shopify.recurringApplicationCharge().updateOrCreate({...}).post().then(recurringApplicationCharge => {
  console.log(recurringApplicationCharge);
});
shopify.recurringApplicationCharge(54646721).get().then(recurringApplicationCharge => {
  console.log(recurringApplicationCharge);
});
shopify.recurringApplicationCharge().get().then(recurringApplicationCharges => {
  console.log(recurringApplicationCharges);
});
shopify.recurringApplicationCharge(54646721).activate().updateOrCreate({...}).post().then(recurringApplicationCharge => {
  console.log(recurringApplicationCharge);
});
shopify.recurringApplicationCharge(54646721).customize().setParams('recurring_application_charge[capped_amount]', 200).put().then(recurringApplicationCharge => {
  console.log(recurringApplicationCharge);
});
shopify.recurringApplicationCharge(54646721).usageCharges().updateOrCreate({...}).post().then(usageCharge => {
  console.log(usageCharge);
});
shopify.recurringApplicationCharge(54646721).usageCharges(79796464).get().then(usageCharge => {
  console.log(usageCharge);
});
shopify.recurringApplicationCharge(54646721).usageCharges().get().then(usageCharges => {
  console.log(usageCharges);
});
shopify.customer().get().then(customers => {
  console.log(customers);
});
shopify.customer().search('Bob country:United States').get().then(customers => {
  console.log(customers);
});
shopify.customer(8464698464).get().then(customers => {
  console.log(customers);
});
shopify.customer().updateOrCreate({...}).post().then(customer => {
  console.log(customer);
});
shopify.customer(8464698464).updateOrCreate({...}).put().then(customer => {
  console.log(customer);
});
shopify.customer().accountActivationUrl().post().then(url => {
  console.log(url);
});
shopify.customer().sendInvite().updateOrCreate({...}).post().then(customerInvite => {
  console.log(customerInvite);
});
shopify.customer(8464698464).order().get().then(orders => {
  console.log(orders);
});
shopify.customer(8464698464).address().get().then(addresses => {
  console.log(addresses);
});
shopify.customer(8464698464).address(79464613).get().then(address => {
  console.log(address);
});
shopify.customer(8464698464).address().updateOrCreate({...}).post().then(address => {
  console.log(address);
});
shopify.customer(8464698464).address(79464613).updateOrCreate({...}).put().then(address => {
  console.log(address);
});
shopify.customer(8464698464).address(79464613).delete().then(address => {
  console.log(address);
});
shopify.customer(8464698464).address().setParams('address_ids', '1053317288').setParams('operation', 'destroy').put().then(address => {
  console.log(address);
});
shopify.customer(8464698464).address(79464613).default().put().then(address => {
  console.log(address);
});
shopify.customerSavedSearch().get().then(savedSearches => {
  console.log(savedSearches);
});
shopify.customerSavedSearch(5646464987).get().then(savedSearch => {
  console.log(savedSearch);
});
shopify.customerSavedSearch(5646464987).customer().get().then(savedSearch => {
  console.log(savedSearch);
});
shopify.customerSavedSearch().updateOrCreate({...}).post().then(savedSearch => {
  console.log(savedSearch);
});
shopify.customerSavedSearch(5646464987).updateOrCreate({...}).put().then(savedSearch => {
  console.log(savedSearch);
});
shopify.priceRule().updateOrCreate({...}).post().then(priceRule => {
  console.log(priceRule);
});
shopify.priceRule(98746464).updateOrCreate({...}).put().then(priceRule => {
  console.log(priceRule);
});
shopify.priceRule().get().then(priceRules => {
  console.log(priceRules);
});
shopify.priceRule(98746464).get().then(priceRule => {
  console.log(priceRule);
});
shopify.article().author().get().then(authors => {
  console.log(authors);
});
shopify.article().tag().get().then(tags => {
  console.log(tags);
});
shopify.blog().get().then(blogs => {
  console.log(blogs);
});
shopify.blog(21955412054).get().then(blog => {
  console.log(blog);
});
shopify.blog(21955412054).article().get().then(articles => {
  console.log(articles);
});
shopify.blog(21955412054).article(28384952406).get().then(article => {
  console.log(article);
});
shopify.blog(21955412054).article(28384952406)
  .updateOrCreate({
    "article": {
      id: 28384952406,
      "title": "My new Lorem Ipsum",
      "author": "test test",
      "tags": "Lorem Ipsum",
      "body_html": "<strong>Lorem Ipsum</strong><span> Lorem Ipsum",
      "published_at": new Date().toUTCString(),
      "image": {
        name: 'opinion',
        src: "example.jpg",
        alt: "My new Article title",
      }
    }
  }).put().then(article => {
  console.log(article);
});
shopify.Comments().updateOrCreate({
  "comment": {
    "body": "Lorem Ipsum",
    "author": "test test",
    "email": "[email protected]",
    "blog_id": 21955412054,
    "article_id": 28384952406
  }
}).post().then(comment => {
  console.log(comment);
});
shopify.Comments(['22424879190']).updateOrCreate({
  "comment": {
    id: 22424879190,
    published_at: new Date().toUTCString(),
  }
}).put().then(comment => {
  console.log(comment);
});
shopify.Comments(['22424879190', 'approve']).post().then(commentApprove => {
  console.log(commentApprove);
});
shopify.Comments(['22424879190', 'spam']).post().then(commentSpam => {
  console.log(commentSpam);
});
shopify.Comments(['22424879190', 'not_spam']).post().then(commentNotSpam => {
  console.log(commentNotSpam);
});
shopify.Comments(['22424879190', 'remove']).post().then(commentRemove => {
  console.log(commentRemove);
});
shopify.Comments(['22424879190', 'restore']).post().then(commentRestore => {
  console.log(commentRestore);
});
shopify.Pages().get().then(pages => {
  console.log(pages);
});
shopify.Pages().sinceId('18521653334').get().then(pagesSince => {
  console.log(pagesSince);
});
shopify.Redirects().get().then(redirects => {
  console.log(redirects);
});
shopify.Redirects([36784537686]).get().then(redirect => {
  console.log(redirect);
});
shopify.ScriptTags().get().then(scriptTags => {
  console.log(ScriptTags);
});
shopify.theme().get().then(themes => {
    console.log(themes);
});
shopify.theme().updateOrCreate({
  "theme": {
    "name": "Dont delete",
    "src": "https://****/theme/dont-delete.zip",
    "role": "unpublished",
  }
}).post().then(theme => {
  console.log(theme);
});
shopify.theme(70895304768).get().then(theme => {
  console.log(theme);
});
shopify.theme(70895304768).delete().then(theme => {
  console.log(theme);
});
shopify.theme(70895304768).asset().get().then(assets => {
  console.log(assets);
});
shopify.theme(70895304768).asset().ofKey('assets/ajax-loader.gif').get().then(asset => {
  console.log(asset);
});
shopify.theme(70895304768).asset().updateOrCreate({
  asset: {
    key: 'config/settings_new.json',
    value: JSON.stringify({
      data: {
        id: '70895403072',
      }
    }),
  }
}).put().then(asset => {
  console.log(asset);
});
shopify.product('1333385494614').fields('id,images,title').get().then(products => {
  console.log(products);
});
shopify.smartCollection().get().then(collections => {
  console.log(collections);
});
shopify.smartCollection().count().get().then(collectionCount => {
  console.log(collectionCount);
});
shopify.smartCollection([1234566]).get().then(collection => {
  console.log(collection);
});
shopify.smartCollection([1234566, 'order']).setParams('products[]', '921728736').setParams('products[]', '632910392').put().then(collection => {
  console.log(collection);
});
shopify.smartCollection([1234566, 'order']).setParams('sort_order', 'alpha-desc').put().then(collection => {
  console.log(collection);
});

Available resources and methods