简体   繁体   中英

getaddrinfo ENOTFOUND error Shopify getSubscriptionUrl Shopify Admin API GraphQL

I'm attempting to setup a Shopify recurring subscription app written in React/Node, but I get a FetchError when I call the following code from my server.js

The Error:

FetchError: request to https://[ACCESS_TOKEN]/admin/api/2020-10/graphql.json failed, reason: getaddrinfo ENOTFOUND [ACCESS_TOKEN]
  at ClientRequest.<anonymous> (/Users/cormachayden/Desktop/apps/easy-tok/node_modules/node-fetch/lib/index.js:1461:11)
  at ClientRequest.emit (events.js:315:20)
  at TLSSocket.socketErrorListener (_http_client.js:469:9)
  at TLSSocket.emit (events.js:315:20)
  at emitErrorNT (internal/streams/destroy.js:106:8)
  at emitErrorCloseNT (internal/streams/destroy.js:74:3)
  at processTicksAndRejections (internal/process/task_queues.js:80:21)

My Code:

  const getSubscriptionUrl = async (accessToken, shop, returnUrl = process.env.HOST) => {
  const subscirptionQuery = JSON.stringify({
    query: `mutation {
      appSubscriptionCreate(
        name: "Easy Tok Premium"
        lineItems: {
          plan: {
            appRecurringPricingDetails: {
              price: { amount: 4.0, currencyCode: USD}
            }
          }
        }
        test: true
        returnUrl: "https://${shop}.myshopify.com/admin/apps/easy-tok"
      ) {
        confirmationUrl
      }
    }`
  });

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

  const responseJson = await response.json();
  return responseJson.data.appSubscriptionCreate.confirmationUrl;
};

module.exports = getSubscriptionUrl;

The same error occurs both locally and when I deploy to Heroku

Your shop variable is returning your AccessToken and not shop_name.myshopify.com . So your request is becoming https://ACESS_TOKEN/admin/api/2020-10/graphql.json which is invalid.

Please double check your shop variable and where are you setting this and please generate a new access token immediately since you shouldn't provide your AccessToken publicly at any cost.

PS: I edited your question to remove the token for security reasons, (have in mind that the history will still keep it, so please change it)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM