How to use shopify-api-node - 7 common examples

To help you get started, we’ve selected a few shopify-api-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactioncommerce / reaction / imports / plugins / included / connectors-shopify / server / methods / import / customers.js View on Github external
async "connectors/shopify/import/customers"(options) {
    check(options, Match.Maybe(Object));
    if (!Reaction.hasPermission(connectorsRoles)) {
      throw new Meteor.Error(403, "Access Denied");
    }

    const apiCreds = getApiInfo();
    const shopify = new Shopify(apiCreds);
    const shopId = Reaction.getShopId();
    const limit = 250; // Shopify returns a maximum of 250 results per request
    const ids = [];
    const opts = Object.assign({}, {
      published_status: "published",
      limit
    }, { ...options });

    try {
      const customerCount = await shopify.customer.count();
      const numPages = Math.ceil(customerCount / limit);
      const pages = [...Array(numPages).keys()];
      Logger.info(`Shopify Connector is preparing to import ${customerCount} customers`);

      for (const page of pages) {
        Logger.debug(`Importing page ${page + 1} of ${numPages} - each page has ${limit} products`);
github reactioncommerce / reaction / imports / plugins / included / connectors-shopify / server / methods / api / products.js View on Github external
async "connectors/shopify/api/products/count"(options) {
    check(options, Match.Maybe(Object));

    if (!Reaction.hasPermission(connectorsRoles)) {
      throw new Meteor.Error("access-denied", "Access denied");
    }

    const apiCreds = getApiInfo();
    const shopify = new Shopify(apiCreds);
    const opts = Object.assign({}, { published_status: "published" }, { ...options }); // eslint-disable-line camelcase

    try {
      const count = await shopify.product.count(opts);
      return count;
    } catch (err) {
      Logger.error("Something went wrong during Shopify products count");
    }
  }
};
github reactioncommerce / reaction / imports / plugins / included / connectors-shopify / server / methods / webhooks / webhooks.js View on Github external
throw new Meteor.Error("access-denied", "Access denied");
    }

    // This code is duplicated in `../api/api`
    // But is left here intentionally as we are updating the specific shopifyPkg that this returns later in this method
    const shopifyPkg = Reaction.getPackageSettingsWithOptions({
      shopId: Reaction.getShopId(),
      name: "reaction-connectors-shopify"
    });

    if (!shopifyPkg) {
      throw new Meteor.Error("server-error", `No shopify package found for shop ${Reaction.getShopId()}`);
    }

    const { settings } = shopifyPkg;
    const shopify = new Shopify({
      apiKey: settings.apiKey,
      password: settings.password,
      shopName: settings.shopName
    });

    const host = options.webhooksDomain || Meteor.absoluteUrl();
    const webhookAddress = `${host}webhooks/shopify/${options.topic.replace(/\//g, "-")}?shopId=${Reaction.getShopId()}`;

    try {
      let shopifyId;
      // Create webhook on Shopify if it isn't installed yet
      const webhooks = await shopify.webhook.list({
        address: webhookAddress
      });
      if (webhooks.length === 0) {
        const webhookResponse = await shopify.webhook.create({
github reactioncommerce / reaction / imports / plugins / included / connectors-shopify / server / methods / export / orders.js View on Github external
export async function exportToShopify(doc) {
  const numShopOrders = doc.billing.length; // if we have multiple billing, we have multiple shops
  Logger.debug(`Exporting ${numShopOrders} order(s) to Shopify`);
  const shopifyOrders = [];
  for (let index = 0; index < numShopOrders; index += 1) {
    // send a shopify order once for each merchant order
    const { shopId } = doc.billing[index];
    const apiCreds = getApiInfo(shopId);
    const shopify = new Shopify(apiCreds);
    const existingCustomerQuery = await isExistingCustomer(doc.billing[index].address, doc.email, shopify); // eslint-disable-line no-await-in-loop
    // this should never happen but I want a meaningful error here in case it does
    if (existingCustomerQuery.length > 1) {
      throw new Meteor.Error("duplicate-customer", "Discovered more than one customer in Shopify. Cannot continue");
    }
    const existingCustomer = existingCustomerQuery[0];
    const shopifyOrder = convertOrderToShopifyOrder(doc, index, shopId, existingCustomer);
    Logger.debug("sending shopify order", shopifyOrder, doc._id);
    const newShopifyOrder = await shopify.order.create(shopifyOrder); // eslint-disable-line no-await-in-loop
    markExported(newShopifyOrder, shopId, doc);
    shopifyOrders.push(newShopifyOrder);
  }
  return shopifyOrders;
}
github airmiha / create-shopify-app / server / routes / shopify.js View on Github external
const getShopifyApi = session => {
    const { shopify: { shop: shopUrl, token } } = session;

    return new ShopifyApi({
      shopName: shopUrl.split('.')[0],
      accessToken: token
    });
  };
github reactioncommerce / reaction / imports / plugins / included / connectors-shopify / server / methods / api / credentials.js View on Github external
async "connectors/shopify/api/credentials/test"() {
    if (!Reaction.hasPermission(connectorsRoles)) {
      throw new Meteor.Error("access-denied", "Access denied");
    }

    const apiCreds = getApiInfo();
    try {
      const shopify = new Shopify(apiCreds);
      await shopify.product.count();
    } catch (err) {
      return false;
    }
    return true;
  }
};
github roevc / metalsmith-shopify / src / utils.js View on Github external
export function loadShopify(options) {
  return new Shopify(options.shopName, options.apiKey, options.password);
}

shopify-api-node

Shopify API bindings for Node.js

MIT
Latest version published 11 days ago

Package Health Score

87 / 100
Full package analysis

Popular shopify-api-node functions