Method PUT gets error CORS

YoDev
Shopify Partner
1 0 0

On the Account page, a button that I made. There will be an Order id value on the button. The Order tag on the order id that is sent from the button will be updated when the button is clicked. But I'm unable to solve my CORS issue. I have no idea how to resolve it. Kindly let me know.
Here my code:

 

 

function updateOrderTags(orderId) {
    const shopifyStore = 'Shopify_id';
    const accessToken = 'Token';
    const updateTagsUrl = `https://${shopifyStore}.myshopify.com/admin/api/2023-10/orders/${orderId}.json`;

    var xhr = new XMLHttpRequest();
    xhr.open('PUT', updateTagsUrl, true);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.setRequestHeader('X-Shopify-Access-Token', accessToken);
    xhr.withCredentials = true;

    xhr.onload = function () {
      if (xhr.status >= 200 && xhr.status < 300) {
        console.log('Success:', xhr.responseText);
        customerRequireTaxModal.show();
      } else {
        console.error('Error:', xhr.status, xhr.statusText, xhr.responseText);
      }
    };

    xhr.onerror = function () {
      console.error('Network Error');
    };

    xhr.send(JSON.stringify({
      order: {
        id: orderId,
        tags: 'TaxInvoice',
      },
    }));
  }

  
    var customerRequireTaxModal = new bootstrap.Modal(document.getElementById('customerRequireTax'));

    document.querySelector('.tax.invoice a').addEventListener('click', function () {
      var orderId = this.getAttribute('data-order-id');
      updateOrderTags(orderId);
    });

 

 

Replies 0 (0)