trouble accessing my Shopify store data using the Admin GraphQL API

I’m encountering issues when trying to access my Shopify store data through the Admin GraphQL API (2024-07). I am using this API within a Google Sheets script to pull data directly into my spreadsheet. My REST API setup for similar operations works without any problems, but the GraphQL API consistently returns errors (attached )

Has anyone encountered a similar issue with the Shopify Admin GraphQL API when used in Google Sheets? Any insights or suggestions would be greatly appreciated.

Admin API access scopes for my Installed app:

Admin API access scopes
read_analytics, read_apps, read_assigned_fulfillment_orders, write_assigned_fulfillment_orders, read_customer_events, write_checkout_branding_settings, read_checkout_branding_settings, write_custom_pixels, read_custom_pixels, write_customers, read_customers, write_discounts, read_discounts, write_discovery, read_discovery, write_draft_orders, read_draft_orders, write_files, read_files, write_fulfillments, read_fulfillments, write_gift_cards, read_gift_cards, write_inventory, read_inventory, write_legal_policies, read_legal_policies, write_locations, read_locations, write_marketing_events, read_marketing_events, write_merchant_managed_fulfillment_orders, read_merchant_managed_fulfillment_orders, write_metaobject_definitions, read_metaobject_definitions, write_metaobjects, read_metaobjects, write_online_store_navigation, read_online_store_navigation, write_online_store_pages, read_online_store_pages, write_order_edits, read_order_edits, write_orders, read_orders, write_packing_slip_templates, read_packing_slip_templates, write_payment_customizations, read_payment_customizations, write_payment_terms, read_payment_terms, write_pixels, read_pixels, write_price_rules, read_price_rules, write_product_feeds, read_product_feeds, write_product_listings, read_product_listings, write_products, read_products, write_publications, read_publications, write_purchase_options, read_purchase_options, write_reports, read_reports, write_resource_feedbacks, read_resource_feedbacks, write_returns, read_returns, write_channels, read_channels, write_script_tags, read_script_tags, write_shipping, read_shipping, write_locales, read_locales, write_markets, read_markets, read_shopify_payments_accounts, read_shopify_payments_bank_accounts, write_shopify_payments_disputes, read_shopify_payments_disputes, read_shopify_payments_payouts, write_content, read_content, write_store_credit_account_transactions, read_store_credit_account_transactions, read_store_credit_accounts, write_themes, read_themes, write_third_party_fulfillment_orders, read_third_party_fulfillment_orders, write_translations, read_translations, read_all_cart_transforms, write_all_checkout_completion_target_customizations, read_all_checkout_completion_target_customizations, write_cart_transforms, read_cart_transforms, read_cash_tracking, write_companies, read_companies, write_custom_fulfillment_services, read_custom_fulfillment_services, write_customer_data_erasure, read_customer_data_erasure, write_customer_merge, read_customer_merge, write_delivery_customizations, read_delivery_customizations, write_delivery_option_generators, read_delivery_option_generators, write_discounts_allocator_functions, read_discounts_allocator_functions, write_fulfillment_constraint_rules, read_fulfillment_constraint_rules, write_gates, read_gates, write_order_submission_rules, read_order_submission_rules, write_validations, read_validations, write_theme_code, read_shopify_payments_provider_accounts_sensitive, write_privacy_settings, read_privacy_settings
Webhook version
2024-07

My JavaScript code in google sheet :

const SHOPIFY_STORE_URL = 'https://{store_name}.myshopify.com';
const SHOPIFY_API_VERSION = '2024-07';
const SHOPIFY_ACCESS_TOKEN = '{access_token}';

function fetchAndLogProductData() {
  Logger.log('Starting fetchAndLogProductData...');

  const url = `${SHOPIFY_STORE_URL}/admin/api/${SHOPIFY_API_VERSION}/graphql.json`;
  Logger.log(`Request URL: ${url}`);

  const query = `
    query {
      products(first: 5) {
        edges {
          node {
            id
            title
            vendor
            productType
            handle
          }
        }
      }
    }
  `;
  Logger.log('GraphQL query constructed:');
  Logger.log(query);

  const options = {
    method: 'POST',
    headers: {
      'X-Shopify-Access-Token': SHOPIFY_ACCESS_TOKEN,
      'Content-Type': 'application/json',
    },
    payload: JSON.stringify({ query: query }),
    muteHttpExceptions: true,
  };
  Logger.log('Request options set:');
  Logger.log(JSON.stringify(options, null, 2));

  try {
    Logger.log('Sending request to Shopify API...');
    const response = UrlFetchApp.fetch(url, options);

    const responseCode = response.getResponseCode();
    const responseText = response.getContentText();

    Logger.log(`Response Code: ${responseCode}`);
    Logger.log(`Response Text: ${responseText}`);

    if (responseCode !== 200) {
      Logger.log(`Error: Received ${responseCode} from Shopify API.`);
      Logger.log(`Response content: ${responseText}`);
      throw new Error(`Request failed with code ${responseCode}`);
    }

    const data = JSON.parse(responseText);
    Logger.log('Response parsed successfully:');
    Logger.log(JSON.stringify(data, null, 2));

    const products = data.data.products.edges;

    if (products.length === 0) {
      Logger.log('No products found.');
    } else {
      Logger.log('Products retrieved:');
      products.forEach(product => {
        Logger.log(`Product ID: ${product.node.id}, Title: ${product.node.title}`);
      });
    }
  } catch (error) {
    Logger.log(`Error occurred: ${error.message}`);
    Logger.log('Stack Trace:');
    Logger.log(error.stack);
  }

  Logger.log('fetchAndLogProductData execution completed.');
}

My error log:

10:35:55 AM Notice Execution started
10:35:55 AM Info Starting fetchAndLogProductData...
10:35:55 AM Info Request URL: https://{store_name}.myshopify.com/admin/api/2024-07/graphql.json
10:35:55 AM Info GraphQL query constructed:
10:35:55 AM Info 
    query {
      products(first: 5) {
        edges {
          node {
            id
            title
            vendor
            productType
            handle
          }
        }
      }
    }
10:35:55 AM Info Request options set:
10:35:55 AM Info {
  "method": "POST",
  "headers": {
    "X-Shopify-Access-Token": "{access_token}",
    "Content-Type": "application/json"
  },
  "payload": "{\"query\":\"\\n    query {\\n      products(first: 5) {\\n        edges {\\n          node {\\n            id\\n            title\\n            vendor\\n            productType\\n            handle\\n          }\\n        }\\n      }\\n    }\\n  \"}",
  "muteHttpExceptions": true
}
10:35:55 AM Info Sending request to Shopify API...
10:35:56 AM Info Response Code: 404
10:35:56 AM Info Response Text: {"errors":"Not Found"}
10:35:56 AM Info Error: Received 404 from Shopify API.
10:35:56 AM Info Response content: {"errors":"Not Found"}
10:35:56 AM Info Error occurred: Request failed with code 404
10:35:56 AM Info Stack Trace:
10:35:56 AM Info Error: Request failed with code 404
    at fetchAndLogProductData (Code:61:13)
    at __GS_INTERNAL_top_function_call__.gs:1:8
10:35:56 AM Info fetchAndLogProductData execution completed.
10:35:56 AM Notice Execution completed

just found solution :slightly_smiling_face: … ‘https://{store_name}.myshopify.com’; should be in original format as Ex: ‘https://do97567-2.myshopify.com’; do NOT use mystoredomain.myshopify.com

const SHOPIFY_STORE_URL = 'https://{store_name}.myshopify.com';
const SHOPIFY_API_VERSION = '2024-07';
const SHOPIFY_ACCESS_TOKEN = '{access_token}';

How does one find the “original format”?

Thanks bro, I have spent hours struggling with this issue, this is the workaround!

its under your shopify store settings > domains > and you will see on of them in this format “do9109-1.myshopify.com

or simply lookup in url link while logged in to your shopify store

I believe they intentionally did it, but they didn’t describe it in their documents. :slightly_smiling_face: