Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Multiple Custom Apps on Same Codebase

Tyler King edited this page Nov 24, 2020 · 8 revisions

Shopify now has limitations on unpublished apps. Custom Apps can only be used on one store. This is an issue if you have a "private" app you wish to share with your clients, but use the same codebase.

This solution allows for swapping out API keys on-the-fly to a Custom App's keys.

In your config/shopify-app.php's api_init option, you would do:

use Osiset\BasicShopifyAPI\BasicShopifyAPI;
use Osiset\BasicShopifyAPI\Options;
use Osiset\BasicShopifyAPI\Session;
use Illuminate\Http\Request;

    // ...

    'api_init' => function (Options $opts, ?Session $session, Request $request) {
        $ts = Config::get('shopify-app.api_time_store');
        $ls = Config::get('shopify-app.api_limit_store');
        $sd = Config::get('shopify-app.api_deferrer');

        $shop = $session ? $session->getShop() : $request->query('shop');
        if ($shop) {
            $shopDomain = preg_replace('/[^A-Z0-9]/', '', strtoupper(explode('.', $shop)[0]));
            $opts->setApiKey(env("API_KEY_{$shopDomain}"));
            $opts->setApiSecret(env("API_SECRET_{$shopDomain}"));
        }

        return new BasicShopifyAPI(
            $opts,
            new $ts(),
            new $ls(),
            new $sd()
        );
    },

This will pull API key and secret from your environment variables. So, if a shop domain is charles-store.myshopify.com, you would make two entries in your environment variables:

API_KEY_CHARLESSTORE="66d7f69b713b201e06805db4d6f9bcefa"
API_SECRET_CHARLESSTORE="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"

Now, anytime the API interface is called for the shop, it will use the keys defined for that shop.

Welcome to the wiki!

Please see the homepage for a list of relevant pages.

Clone this wiki locally