Oauth error invalid_request: Could not find Shopify API application with api_key

85 4 14

An old Client ID seems to be stuck in the auth url...

I started with the Node React Tutorial and had everything working fine. Then made a copy and made some modifications to the server.js file to include read_orders, write_orders. I try authenticating with: 

I got the following error which shows it was trying to use the old API_KEY. 
You can see my current server.js: 


const dotenv = require('dotenv');
const Koa = require('koa');
const next = require('next');
const { default: createShopifyAuth } = require('@shopify/koa-shopify-auth');
const { verifyRequest } = require('@shopify/koa-shopify-auth');
const session = require('koa-session');

const { default: graphQLProxy } = require('@shopify/koa-shopify-graphql-proxy');
const { ApiVersion } = require('@shopify/koa-shopify-graphql-proxy');

const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

const { SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env;

app.prepare().then(() => {

    const server = new Koa();
    server.use(session({ secure: true, sameSite: 'none' }, server));
    server.keys = [SHOPIFY_API_SECRET_KEY];

          apiKey: SHOPIFY_API_KEY,
          secret: SHOPIFY_API_SECRET_KEY,
          scopes: ['read_products', 'write_products', 'read_orders, write_orders', 'read_draft_orders', 'write_draft_orders'],
          afterAuth(ctx) {
            const { shop, accessToken } = ctx.session;
            ctx.cookies.set('shopOrigin', shop, {
                httpOnly: false,
                secure: true,
                sameSite: 'none'

    console.log("APIKEY:" + server.apiKey);
    console.log("SCOPE:" + server.scopes);

    server.use(graphQLProxy({version: ApiVersion.October19}))
    server.use(async (ctx) => {
      await handle(ctx.req, ctx.res);
      ctx.respond = false;
      ctx.res.statusCode = 200;

    server.listen(port, () => {
        console.log(`> Ready on http://localhost:${port}`);


My .env file has the correct current apps API KEY and Secret Key. 


It seems there is some cache of the earlier API key or another setting inside Shopify that I need to set the new API Key. 
Any help on this point would be great.
85 4 14

This is an accepted solution.

Sequence of tests I did to resolve this were: 

  1. Delete all other test apps (original one had the API_KEY that was stuck in Shopify cache)
  2. Created a new app in Shopify using same code 
  3. Verify .env file had correct new api_key (it did)
  4. Verify the Shopify Partner Account / App / App Settings api_key matched the .env file api_key (it did)
  5. Clear cache of web browser (didn't change anything)
  6. Restarted node server (didn't change anything)
  7. Killed all processes running on port 3000 (didn't change anything)
  8. Changed to different port 
  9. Restarted server (suddenly worked)

Why all the above was necessary I don't know. Would be good to have some insight from Shopify on correct process to resolve this issue. This all started with simply needing to add scope to an existing app and not being able to see the changes take effect when re-authing app. 


Shopify Partner
40 3 18

This is an accepted solution.

My immediate guess based on the original issue of the change not being seen then restarting the server seeming to fix everything is that this might have been a caching issue. I have seen and heard of similar issues when hosting locally and tunneling through Ngrok and the sort.