0.0.3 • Published 2 years ago

@dbadbadba/shopify-api v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@dbadbadba/shopify-api

License: MIT npm version

This library is a fork of @shopify/shopify-api-js and it provides support for the backends of TypeScript/JavaScript.

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.

import '@shopify/shopify-api/adapters/node';
import '@shopify/shopify-api/adapters/cf-worker';

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

Call shopifyApi (see reference) 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 reference documentation for details on all the methods provided by this package.

See the specific documentation in the Guides section for high-level 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.

Guides