New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@shopify/shopify-api

Package Overview
Dependencies
Maintainers
19
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/shopify-api

Shopify API Library for Node - accelerate development with support for authentication, graphql proxy, webhooks

  • 6.0.0-rc11
  • next
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
101K
decreased by-2.52%
Maintainers
19
Weekly downloads
 
Created
Source

@shopify/shopify-api

License: MIT npm version

This library provides support for the backends of TypeScript/JavaScript Shopify apps to access the Shopify Admin API, by making it easier to perform the following actions:

  • Creating online or offline access tokens for the Admin API via OAuth
  • Making requests to the REST API
  • Making requests to the GraphQL API
  • Register/process webhooks

Once your app has access to the Admin API, you can also access the Shopify Storefront API to run GraphQL queries using the unauthenticated_* access scopes.

This library can be used in any application that runs on one of the supported runtimes. It doesn't rely on any specific framework, so you can include it alongside your preferred stack and only use the features that you need to build your app.

Note: this package will enable your app's backend to work with Shopify APIs, but you'll need to use Shopify App Bridge in your frontend if you're planning on embedding your app into the Shopify Admin.

Requirements

To follow these usage guides, you will need to:

  • have a basic understanding of TypeScript
  • have a Shopify Partner account and development store
  • OR have a test store where you can create a private app
  • have a private or custom app already set up in your test store or partner account
  • use ngrok, in order to create a secure tunnel to your app running on your localhost
  • add the ngrok URL and the appropriate redirect for your OAuth callback route to your app settings
  • have a JavaScript package manager such as yarn installed

Getting started

To install this package, you can run this on your terminal:

# You can use your preferred Node package manager
yarn add @shopify/shopify-api

Note: throughout these docs, we'll provide some examples of how this library may be used in an app using the Express.js framework for simplicity, but you can use it with any framework you prefer, as mentioned before.

The first thing you need to import is the adapter for your app's runtime. This will internally set up the library to use the right defaults and behaviours for the runtime.

Node.js
import '@shopify/shopify-api/adapters/node';
CloudFlare Worker
import '@shopify/shopify-api/adapters/cf-worker';

Next, configure the library - you'll need some values in advance:

Call shopifyApi to create your library object before setting up your app itself:

import '@shopify/shopify-api/adapters/node';
import {shopifyApi, LATEST_API_VERSION} from '@shopify/shopify-api';
import express from 'express';

const shopify = shopifyApi({
  // The next 4 values are typically read from environment variables for added security
  apiKey: 'APIKeyFromPartnersDashboard',
  apiSecretKey: 'APISecretFromPartnersDashboard',
  scopes: ['read_products'],
  hostName: 'ngrok-tunnel-address',
  ...
});

const app = express();

Next steps

Once you configure your app, you can use this package to access the Shopify APIs. See the specific documentation in the Features section for instructions on how to get API access tokens and use them to query the APIs.

As a general rule, apps will want to interact with the Admin API to fetch / submit data to Shopify. To do that, apps will need to:

  1. Create an Admin API access token by going through the OAuth flow.
  2. Set up its own endpoints to:
    1. Fetch the current session created in the OAuth process.
    2. Create a REST or GraphQL API client.
    3. Use the client to query the appropriate Admin API.

Configurations

These are all the configuration values shopifyApi supports.

ValueTypeRequiredDefaultDescription
apiKeystringYes-API key from Partners Dashboard
apiSecretKeystringYes-API secret from Partners Dashboard
scopesstring[] | AuthScopesYes-App scopes
hostNamestringYes-App host name in the format my-host-name.com. Do not include the scheme or leading or trailing slashes
hostScheme"https" | "http"No"https"The scheme for your app's public URL
apiVersionApiVersionNoLATEST_API_VERSIONAPI version your app will be querying. E.g. ApiVersion.January20
isEmbeddedAppbooleanNotrueWhether your app will run within the Shopify Admin
isPrivateAppbooleanNofalseWhether you are building a private app for a store
userAgentPrefixstringNoundefinedAny prefix you wish to include in the User-Agent for requests made by the library
privateAppStorefrontAccessTokenstringNoundefinedFixed Storefront API access token for private apps
customShopDomains(RegExp | string)[]NoundefinedUse this if you need to allow values other than myshopify.com
billingBillingConfigNoundefinedBilling configurations. See documentation for full description
restResourcesShopifyRestResourcesNo-Mounts the given REST resources onto the object. Must use the same version as apiVersion. Learn more about using REST resources
logger{[key: string]: any}No-Tweaks the behaviour of the package's internal logging to make it easier to debug applications
  logger.logAsyncFunctionNo() => Promise<void>Async callback function used for logging, which takes in a LogSeverity value and a formatted message. Defaults to using console calls matching the severity parameter
  logger.levelLogSeverityNoLogSeverity.InfoMinimum severity for which to trigger the log function
  logger.httpRequestsbooleanNofalseWhether to log ALL HTTP requests made by the package. Only works if level is Debug
  logger.timestampsbooleanNofalseWhether to add the current timestamp to every log call

Features

Migrating to v6

Before v6, this library only worked on Node.js runtimes. It now supports multiple runtimes through the use of adapters, more of which can be added over time. If an adapter for the runtime you wish to use doesn't exist, you can create your own adapter by implementing some key functions, or contribute a PR to this repository.

In addition to updating the library to work on different runtimes, we've also improved its public interface to make it easier for apps to load only the features they need from the library. If you're upgrading an existing app on v5 or earlier, please see the migration guide for v6.

Keywords

FAQs

Package last updated on 06 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc