2.2.4 • Published 5 years ago

shopify-sdk v2.2.4

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

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": "psofttech123@gmail.com",
    "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

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago