Oauth error missing_shopify_permission: read_users

Highlighted
Shopify Partner
6 0 1

Hi guys,

 

I'm building an app that query the list of customers and save the result in an array.

 

I've found this code on Shopify 

import gql from 'graphql-tag';
import { Query } from 'react-apollo';
import { Card } from '@shopify/polaris';
import ApolloClient from 'apollo-boost';


const GET_CLIENTS = gql`
    query{
        customers(first:10){
        edges{
            node{
            email
            acceptsMarketing
            firstName
            state
            updatedAt
            verifiedEmail
            }
        }
        }
    }
`;

class ResourceListWithClients extends React.Component {
      render() {
        return (
          <Query query={GET_CLIENTS}>
            {({ data, loading, error }) => {
              if (loading) return <div>Loading…</div>;
              if (error) return <div>{error.message}</div>;
              console.log(data);
              return (
                <Card>
                  <p>stuff here</p>
                </Card>
              );
            }}
          </Query>
        );
      }
    }
    
export default ResourceListWithClients;

I think that this is ok.

 

I also change the scopes in the server.js file

require('isomorphic-fetch');
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');

dotenv.config();
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(server));
    server.keys = [SHOPIFY_API_SECRET_KEY];
    server.use(
        createShopifyAuth({
            apiKey: SHOPIFY_API_KEY,
            secret: SHOPIFY_API_SECRET_KEY,
            scopes: ['read_products', 'write_products', 'read_orders', 'read_users', 'read_customers'],
            afterAuth(ctx) {
                const { shop, accessToken } = ctx.session;
                ctx.cookies.set('shopOrigin', shop, { httpOnly: false });
                ctx.redirect('/');
            },
        }),
    );
    server.use(graphQLProxy({version: ApiVersion.October19}))
    server.use(verifyRequest());
    server.use(async (ctx) => {
        await handle(ctx.req, ctx.res);
        ctx.respond = false;
        ctx.res.statusCode = 200;
        return
    });
    server.listen(port, () => {
        console.log(`> Ready on http://localhost:${port}`);
    });
});

But when I try to launch the app I get this error. 

 

Someone can tell me where I'm wrong?

0 Likes
Highlighted
Shopify Partner
6 0 1

I'm done

0 Likes
Highlighted
Tourist
8 0 1

Can you share your solution? Having the same error.

0 Likes
Highlighted
Pathfinder
83 4 11

Same here. After I changed scope and tried to verify app i started getting oauth error referring to the old API_KEY when my new app uses different key. 

0 Likes
Highlighted
Tourist
8 0 1

For me error ended up being because the users API is a Shopify Plus feature only, and I had to get a Shopify rep to manually enable it for our App API Key.

Highlighted
Pathfinder
83 4 11

I resolved my issue by creating a new app, deleting all earlier apps (the one that had the old API Key), changing the port and restarting the server. Suddenly started working. I'm not sure if changing the port solved it or a combination of the above. Before changing the port I was still getting the error, even after restarting server. Strange, but works now. 

0 Likes