/shopify_app

A Rails Engine for building Shopify Apps

Primary LanguageRubyMIT LicenseMIT

Shopify App

Version Build Status

This gem builds Rails applications that can be embedded in the Shopify Admin.

Introduction | Requirements | Usage | Documentation | Contributing | License

Introduction

This gem includes a Rails engine, generators, modules, and mixins that help create Rails applications that work with Shopify APIs. The Shopify App Rails engine provides all the code required to implement OAuth with Shopify. The default Shopify App generator builds an app that can be embedded in the Shopify Admin and secures it with session tokens.

Requirements

Rails compatibility

  • Use Shopify App <= v7.2.8 if you need to work with Rails 4.

To become a Shopify app developer, you will need a Shopify Partners account. Explore the Shopify dev docs to learn more about building Shopify apps.

This gem requires that you have the following credentials:

OAuth Tunnel in Development

In order to redirect OAuth requests securely to localhost, you'll need to setup a tunnel to redirect from the internet to localhost.

We've validated that Cloudflare Tunnel works with this template.

To do that, you can install the cloudflared CLI tool, and run:

# Note that you can also use a different port
cloudflared tunnel --url http://localhost:3000

You will need to keep this window running to maintain the tunnel during development.

Usage

  1. To get started, create a new Rails app:
$ rails new my_shopify_app
  1. Add the Shopify App gem to my_shopify_app's Gemfile.
$ bundle add shopify_app
  1. Create a .env file in the root of my_shopify_app to specify your Shopify API credentials:
SHOPIFY_API_KEY=<Your Shopify API key>
SHOPIFY_API_SECRET=<Your Shopify API secret>
HOST=<Your SSH tunnel host>

In a development environment, you can use a gem like dotenv-rails to manage environment variables.

  1. Run the default Shopify App generator to create an app that can be embedded in the Shopify Admin:
$ rails generate shopify_app
  1. Run a migration to create the necessary tables in your database:
$ rails db:migrate
  1. Run the app:
$ rails server

See Quickstart to learn how to install your app on a shop.

This app implements OAuth 2.0 with Shopify to authenticate requests made to Shopify APIs. By default, this app is configured to use session tokens to authenticate merchants when embedded in the Shopify Admin.

See Generators for a complete list of generators available to Shopify App.

Documentation

You can find documentation on gem usage, concepts, mixins, installation, and more in /docs.

  • Start with the Generators document to learn more about the generators this gem offers.
  • Check out the Changelog for notes on the latest gem releases.
  • See Troubleshooting for tips on common issues.
  • If you are looking to upgrade your Shopify App version to a new major release, see Upgrading for important notes on breaking changes.

Overview

Quickstart

Troubleshooting

Upgrading

Shopify App

Engine

Mounting the Shopify App Rails Engine provides the following routes. These routes are configured to help install your application on shops and implement OAuth.

Verb Route Action
GET /login Login
POST /login Login
GET /auth/shopify/callback OAuth redirect URI
GET /logout Logout
POST /webhooks/:type Webhook callback

These routes are configurable. See the more detailed Engine documentation to learn how you can customize the login URL or mount the Shopify App Rails engine at nested routes.

To learn more about how this gem authenticates with Shopify, see Authentication.

API Versioning

Shopify's API is versioned. With Shopify App v1.11.0, the included Shopify API gem allows developers to specify and update the Shopify API version they want their app or service to use. The Shopify API gem also surfaces warnings to Rails apps about deprecated endpoints, GraphQL fields and more.

See the Shopify API gem README for more information.