Solved

Shopify App 500 Error for only Collaborator access! Perfect Solution needed!!!

Ryan1118
Excursionist
21 0 7

Hi, Shopify wizards!

I'm currently having very weird issue. I built a Shopify app with React + Node.js. 

The app works fine unless I access it as a collaborator account. 

If I try to access(install or open), it shows 500 internal server error. I'm running the app with PM2, so I can see the error instantly with "pm2 monit"

This is the error I have. 

 >   Error: Internal error. Looks like something went wrong on our end.         
│││Request ID: 80f73226-b636-4136-a4d2-1dbf075b5393 (include this in support requests).        
│││at new ApolloError (/var/www/html/APP_SRC/node_modules/@apollo/client/errors/index.js:26:28  │
│││at Object.next (/var/www/html/APP_SRC/node_modules/@apollo/client/core/QueryManager.js:88:5  │
│││at notifySubscription (/var/www/html/APP_SRC/node_modules/zen-observable/lib/Observable.js:  │
│││at onNotify (/var/www/html/APP_SRC/node_modules/zen-observable/lib/Observable.js:179:3)      │
│││at SubscriptionObserver.next (/var/www/html/APP_SRC/node_modules/zen-observable/lib/Observa  │
│││at /var/www/html/APP_SRC/node_modules/@apollo/client/utilities/observables/iteration.js:4:6  │
│││at Array.forEach (<anonymous>)                                                                
│││at iterateObserversSafely (/var/www/html/APP_SRC/node_modules/@apollo/client/utilities/obse  │
│││at Object.next (/var/www/html/APP_SRC/node_modules/@apollo/client/utilities/observables/Con  │
│││at notifySubscription (/var/www/html/APP_SRC/node_modules/zen-observable/lib/Observable.js:  │
│││at onNotify (/var/www/html/APP_SRC/node_modules/zen-observable/lib/Observable.js:179:3)      │
│││at SubscriptionObserver.next (/var/www/html/APP_SRC/node_modules/zen-observable/lib/Observa  │
│││at /var/www/html/APP_SRC/node_modules/@apollo/client/link/http/createHttpLink.js:100:26      │
│││at process._tickCallback (internal/process/next_tick.js:68:7)

 

This looks like obviously apollo or graphql error. But the weird thing is if I try with merchant account, all good. 

So I thought it might be related to apollo client version problem. I used apollo-boost library. So I upgraded it into @Apollo/client v 3.0 - the latest version. And updated all dependencies and codes although there were not much codes related to it. 

But the issue still persists. 

I checked to see on what part the issue was happening. 

The issue is in `get-subscription-url.js`  The following code is part of the file.

export const getSubscriptionUrl = async (ctx, shop) => {
  console.log("GETTING URL");
  const { client } = ctx;
  const appSubscriptionCreate = await client
    .mutate({
      mutation: RECURRING_CREATE(process.env.HOST)
    })
    .then(response => {
      console.log(
        "NEW URL: ",
        response.data.appSubscriptionCreate.confirmationUrl
      );
      return response.data.appSubscriptionCreate;
    });
    console.log("step 2-1 passed ");

I exactly see "GETTING URL" log, but I don't see "NEW URL: xxxx" log. 

I'm sharing RECURRING_CREATE function as well. 

export function RECURRING_CREATE(url) {
  return gql`
    mutation {
      appSubscriptionCreate(
          name: "Standard Plan"
          returnUrl: "${url}"
          test: ${dev ? true : false}
          lineItems: [
          {
            plan: {
              appRecurringPricingDetails: {
                  price: { amount: 9.99, currencyCode: USD }
              }
            }
          }
          ]
        ) {
            userErrors {
              field
              message
            }
            confirmationUrl
            appSubscription {
              id
            }
        }
    }`;
}

 

And this is how I import `gql` from the updated @Apollo/client

import { gql } from "@apollo/client";

I tried bunch of researches, but haven't got any solutions yet. 

So my concern is...

1. This might be a reason of wrong code?

2. Should I reach to Shopify Staff with this issue?

3. But how come merchant account could work properly, but only Collaborator account? FYI, the collaborator account is `FULL PERMISSION`

4. I'm currently using an old API version. Something like this.. `https://${shop}/admin/api/2019-10/graphql.json`. The old API version might be the reason of this issue? 

 

I'm sharing some relevant posts from others here. 

https://community.shopify.com/c/Shopify-APIs-SDKs/GraphQL-does-not-work-when-logged-in-as-collaborat...

https://community.shopify.com/c/Shopify-APIs-SDKs/Problem-with-Subscription-Webhook-for-Staff-user-N...

https://community.shopify.com/c/Shopify-APIs-SDKs/Apollo-Error-when-running-any-GraphQL-fetch-query/...

 

Some people said me it might be because of Shopify's Internal issue, and try to reload it again. But this issue always happens. 

Hope to a complete solution now.

Thank you in advance.

 

Best Regards,

Ryan.

 

Accepted Solution (1)

syf_
Shopify Staff
95 21 24

This is an accepted solution.

Hi Ryan,

So, the behaviour you're experiencing is expected, and I'd provide some additional context on the issue.

There are some actions that per our business rules only account owners can perform or have access to, and App Subscriptions is one of such. For anything related to App Subscriptions, only the Account Owner can authorise or has access to such information.

Regarding the error you received, it was because the user (staff account with full access in this case) trying to authorise the recurring charge was not the Account Owner. 

Hopefully this helps clarify the error you were getting. If you have any additional questions on this, please do get back to me.

Best,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

syf_
Shopify Staff
95 21 24

This is an accepted solution.

Hi Ryan,

So, the behaviour you're experiencing is expected, and I'd provide some additional context on the issue.

There are some actions that per our business rules only account owners can perform or have access to, and App Subscriptions is one of such. For anything related to App Subscriptions, only the Account Owner can authorise or has access to such information.

Regarding the error you received, it was because the user (staff account with full access in this case) trying to authorise the recurring charge was not the Account Owner. 

Hopefully this helps clarify the error you were getting. If you have any additional questions on this, please do get back to me.

Best,
Seth.

syf_ | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Ryan1118
Excursionist
21 0 7

Thank you @syf_ 

Everything makes sense!

I updated my code to avoid such action as a collaborator account. Everything works fine. 

Thanks!