I’m building a Node.js app that integrates with Shopify’s billing system using their GraphQL Admin API. When I try to create an app subscription, I keep getting a DNS resolution error.
The error message:
FetchError: request to https://[ACCESS_TOKEN]/admin/api/2020-10/graphql.json failed, reason: getaddrinfo ENOTFOUND [ACCESS_TOKEN]
at ClientRequest.<anonymous> (/node_modules/node-fetch/lib/index.js:1461:11)
at ClientRequest.emit (events.js:315:20)
Everyone nailed the main issue, but quick addition - check if your storeName has extra characters or spaces. I’ve seen that cause weird DNS errors even when the .myshopify.com format looks right. Also heads up, that error’s showing your access token in the URL. Make sure you’re not accidentally logging it somewhere.
You’re encountering a DNS error due to your URL lacking the necessary domain part. The URL https://${storeName}/admin/api/2020-10/graphql.json only resolves to the store name, which is incomplete. Instead, you should format it as https://${storeName}.myshopify.com/admin/api/2020-10/graphql.json.
I experienced a similar issue when I was integrating Shopify’s billing API last year. It can be confusing since the access token appears in the error, making it harder to identify the problem. Additionally, consider incorporating error handling for DNS resolutions and API requests, as network issues can occur even with valid URLs. Currently, your code proceeds to access jsonData.data.appSubscriptionCreate.confirmationUrl without checking for possible errors in the API response, which could lead to crashes if the mutation fails.
You’re building the URL incorrectly. In your fetch call, you’ve got https://${storeName}/admin/api/2020-10/graphql.json but it should be https://${storeName}.myshopify.com/admin/api/2020-10/graphql.json. Without the .myshopify.com, it cannot resolve the hostname. I encountered this exact issue when I began using Shopify’s GraphQL API. The error message can be misleading since it shows your access token in the failed URL, so double-check your variables as well. Additionally, using the 2020-10 version is quite outdated. I recommend updating to a more recent version like 2023-10 or 2024-01 to avoid potential deprecation issues in the future. The billing API structure hasn’t changed significantly, so your mutation should still work with the newer versions.
Found your problem right away. Your fetch URL is wrong - you’ve got https://${storeName}/admin/api/2020-10/graphql.json but it should be https://${storeName}.myshopify.com/admin/api/2020-10/graphql.json.
You’re getting DNS errors because you’re missing .myshopify.com in the URL. Your code can’t resolve just the store name as a domain.
Honestly though, manually handling Shopify’s API quirks and URL construction is a massive pain. I’ve dealt with this exact issue way too many times.
Skip the fetch calls and URL formatting headaches - use Latenode instead. It handles Shopify integrations natively and sorts out all the API endpoint stuff automatically. You can build the billing workflow visually without worrying about DNS issues or URL mistakes.
I’ve used it for similar Shopify billing automations and it completely eliminates these technical headaches. GraphQL mutations just work without manual URL construction.