Shopify CLI | GraphQL | Billing API | Message: Internal error. Looks like something went wrong

I’m working on setting up a recurring pricing plan for my public Shopify app.

I’ve used ShopifyCLI to set up my project and I’m trying to utilize the included GraphQL flow (with some tweaks) to achieve this.

Here is my GraphQL Code:

import "isomorphic-fetch";
import { gql } from "apollo-boost";

export function RECURRING_CREATE() {
  return gql`
    mutation AppSubscriptionCreate(
      $name: String!
      $lineItems: [AppSubscriptionLineItemInput!]!
      $returnUrl: URL!
    ) {
      appSubscriptionCreate(
        name: $name
        returnUrl: $returnUrl
        lineItems: $lineItems
      ) {
        userErrors {
          field
          message
        }
        appSubscription {
          id
        }
        confirmationUrl
      }
    }
  `;
}

export const getSubscriptionUrl = async (client, shop) => {
  const confirmationUrl = await client
    .mutate({
      mutation: RECURRING_CREATE(),
      variables: {
        name: "Unlimited Plan",
        returnUrl: `${process.env.HOST}/?shop=${shop}`,
        lineItems: [
          {
            plan: {
              appRecurringPricingDetails: {
                price: {
                  amount: 25.0,
                  currencyCode: "USD",
                },
                interval: "EVERY_30_DAYS",
              },
            },
          },
        ],
      },
    })
    .then((response) => response.data.appSubscriptionCreate.confirmationUrl)
    .catch((error) => {
      console.error(error);
      return "/";
    });

  return confirmationUrl;
};

This code gets called from the server like so:

server.use(
    createShopifyAuth({
      apiKey: SHOPIFY_API_KEY,
      secret: SHOPIFY_API_SECRET,
      scopes: [SCOPES],

      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop, accessToken } = ctx.state.shopify;

        const apolloClient = createClient(shop, accessToken);

        // Redirect to app with shop parameter upon auth
        ctx.redirect(getSubscriptionUrl(apolloClient, shop));
      },
    })
  );

However, when trying to install the app the server throws this error:

[GraphQL error]: Message: Internal error. Looks like something went wrong on our end.
┃ Request ID: 1829e16b-b5dd-4e45-b083-7f8ac0da1a66 (include this in support requests)., Location: undefined, Path: undefined
┃ ApolloError: GraphQL error: Internal error. Looks like something went wrong on our end.

I’ve been unable to find sufficient information about this error, that being said it appears something might be wrong with my GraphQL mutation document. I’ve tried several variations including the example on the doc’s page with no success.

Any advice? Thanks.

Small update.

I realized I wasn’t waiting for a response from getSubscriptionUrl().

However, now I’m still unable to get a valid response back. I rewrote the getSubscriptionUrl() function like so:

export const getSubscriptionUrl = async (ctx, url) => {
  const query = JSON.stringify({
    query: `mutation {
      appSubscriptionCreate(
          name: "Unlimited Plan"
          returnUrl: "${url}"
          test: true
          lineItems: [
            {
              plan: {
                appRecurringPricingDetails: {
                  price: {
                    amount: 25.0,
                    currencyCode: USD,
                  },
                  interval: EVERY_30_DAYS,
                },
              },
            }
          ]
        ) {
            userErrors {
              field
              message
            }
            confirmationUrl
            appSubscription {
              id
            }
        }
    }`,
  });

  const { shop, accessToken } = ctx.state.shopify;

  const response = await fetch(
    `https://${shop}/admin/api/2021-10/graphql.json`,
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-Shopify-Access-Token": accessToken,
      },
      body: query,
    }
  );

  const responseJson = await response.json();
  console.log(responseJson);
  const confirmationUrl =
    responseJson.data?.appSubscriptionCreate?.confirmationUrl;

  if (!!confirmationUrl) {
    return ctx.redirect(confirmationUrl);
  } else {
    return ctx.redirect("/");
  }
};

And the server.js to match:

server.use(
    createShopifyAuth({
      apiKey: SHOPIFY_API_KEY,
      secret: SHOPIFY_API_SECRET,
      scopes: [SCOPES],

      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop, accessToken } = ctx.state.shopify;

        // Redirect to app with shop parameter upon auth
        const returnUrl = `${HOST}?host=${HOST}&shop=${shop}`;
        await getSubscriptionUrl(ctx, returnUrl);
      },
    })
  );

At this point, I have tried a few different GraphQL API versions and connection methods and I don’t have any more meaningful error messages.

Here is my latest Request ID: 6da6b32c-0f07-4d08-bca2-09733ef73ad1

1 Like

Revisiting this post as it’s gotten some attention recently. Through enough research I was able to identify the cause of this error was permissions based. Simply put, I was not a Shop owner on the dev store I was working on. By bumping up my permissions I was able to perform the mentioned mutations successfully. Hopes this helps someone else :slightly_smiling_face:

That being said, the lack of clear messaging around this is extremely frustrating and I hope Shopify has/will address this.