3

I'm using Shopify Node Api to build my first proper app. I'm trying to build an express.js boilerplate that I can release as an NPM package. Every app I've built so far has been private - but this is my first attempt at one using Oauth.

https://github.com/christophergregory/shopify-node-api

I'm trying to figure out how I can install the app to a particular shop. I do not know how to get the store name. When someone clicks "install app" - I'm guessing a parameter is sent? However, I wont get an install button until the app is published on the store... (catch 22?)

So far, I've hard wired the store name into the config. I then hit the main root of the app, and run the install stuff. I then grab the access token and save it to a database.

<!-- language: lang-js -->
var config = {
shop: 'example', // MYSHOP.myshopify.com
// scopes, api-key, api-secret etc..
redirect_uri: 'http://localhost:3000/finish_auth',
verbose: false,
nonce: '' // a randomly selected value unique for each authorization request
}

var Shopify = new shopifyAPI(config);
var auth_url = Shopify.buildAuthURL();

app.get('/', function(req, res) {
 res.redirect(auth_url);
});

How would I make this dynamic - so it can be installed to any store?

Rob
  • 1,576
  • 3
  • 22
  • 52
  • I've sort of figured it by using a form to prompt the store owner to enter their details - but it just feels a bit naff.... – Rob Jan 26 '16 at 19:48
  • 2
    The basic process here is to setup an endpoint that will kick off the oauth process (e.g. /install?shop=MYSTORE.myshopify.com). In order to do so, we need to know which shop to connect to so we have to ask the user for those details. Please note that if you plan on selling this app on the shopify app store, they will automatically send the user to your endpoint with the shop query parameter already in place. – ChrisC Jan 27 '16 at 14:21
  • Wow - so Shopify will append ?shop=MYSTORE.myshopify.com to the end of my endpoint? That's awesome!! Just what I was after :) Thanks! – Rob Jan 27 '16 at 15:23
  • But how to identify the shop domain for later activities in requests that get originated with in the app. They don't have this query parameter? Do we have to maintain a session? I asked a new question here. https://stackoverflow.com/questions/47432209/shopify-get-shop-domain-inside-a-app –  Nov 22 '17 at 14:47

0 Answers0