Link Private App

Hello, I created a custom app and allowed read and manage orders. I’m trying to link it via:

I used x and y to from above ^ to link it.

document.addEventListener('DOMContentLoaded', function() {
  // Get the "Check Order" button
  const checkOrderBtn = document.getElementById('checkOrderBtn');

  // Add event listener for the button
  checkOrderBtn.addEventListener('click', function() {
    // Get the form elements
    const nameField = document.getElementById('ContactForm-name');
    const emailField = document.getElementById('ContactForm-email');
    const orderNumberField = document.getElementById('ContactForm-order-number');
    const returnTypeField = document.getElementById('ContactForm-return-type');

    // Check if all required fields are filled
    if (!nameField.value || !emailField.value || !orderNumberField.value || !returnTypeField.value) {
      alert("Please fill in all required fields.");
      return;
    }

    // If all fields are filled, proceed with order check
    var orderNumber = orderNumberField.value;
    console.log('Checking order:', orderNumber); // Add this log to verify order number

    // Call the function to check if order exists
    getOrder(orderNumber);
  });

  
  function getOrder(orderNumber) {
  const storeUrl = '3829de-3';  // Replace with your store URL
  const apiKey = 'x';  // Replace with your private app API key
  const apiPassword = 'y';  // Replace with your private app API password

  const apiUrl = `https://${storeUrl}.myshopify.com/admin/api/2023-01/orders.json?name=${orderNumber}`;
    console.log('API URL:', apiUrl);  // Add this log to check if the URL is correct

    fetch(apiUrl, {
      method: 'GET',
      headers: {
        'Authorization': 'Basic ' + btoa(apiKey + ':' + apiPassword),
      }
    })
    .then(response => {
      console.log('Response status:', response.status); // Log status code
      if (!response.ok) {
        throw new Error('Network response was not ok');
      }
      return response.json();
    })
    .then(data => {
      console.log('Data received:', data); // Log the response data

      if (data.orders && data.orders.length > 0) {
        console.log('Order Found:', data.orders[0]);
        alert("Order found!");
      } else {
        console.log('Order not found');
        alert("Order not found.");
      }
    })
    .catch(error => {
      console.error('Error:', error);
      alert('An error occurred while checking the order.');
    });
  }
});

But when I try to check a valid order, it results in error: ‘An error occurred while checking the order.’

I want to check if the order exists to continue with the refund process but it is not working. How can I check if the order is valid?

You cannot get the order throung storefront @TrendBlend Maybe you can use automation tool like zapier or Make.com to achieve this…