Getting 404 Error When Updating Customer Details Through Shopify REST API

I’m having trouble updating customer information using Shopify’s API through an Ajax call. The request works perfectly in Postman and Chrome, but when I try to run it from my website, I get a 404 error.

I’ve set up a private app with all the necessary permissions and followed Shopify’s documentation. The API call should update the customer’s name, email, and phone number but it’s not working.

Here’s my current implementation:

let firstName = document.getElementById("userFirstName").getAttribute("value");
let lastName = document.getElementById("userLastName").getAttribute("value");
let emailAddr = document.getElementById("userEmail").getAttribute("value");
let phoneNum = document.getElementById("userPhone").getAttribute("value");
let userId = document.getElementById("userId").getAttribute("value");

let userInfo = {
  "customer": {
    "id": userId,
    "first_name": firstName,
    "last_name": lastName,
    "email": emailAddr,
    "phone": phoneNum
  }
};

let userInfoJson = JSON.stringify(userInfo);

jQuery.cookie("session", null);

jQuery.ajax({
  url: 'https://{api_key}:{api_secret}@{store_name}.myshopify.com/admin/api/2022-04/customers/{user_id}.json',
  type: 'PUT',
  cache: false,
  data: userInfoJson,
  crossDomain: true,
  dataType: "JSONP",
  contentType: "application/json; charset=utf-8",
  success: function(data) {
    console.log(data);
  },
  error: function(data) {
    console.log("Error occurred:");
    console.log(data);
  }
});

I switched to JSONP to handle CORS issues. The response shows readyState 4 but still throws the 404 error. Any ideas what might be causing this?

The main issue here is that you’re using dataType “JSONP” for a PUT request, which isn’t supported by the Shopify API. JSONP only works with GET requests and Shopify’s REST API doesn’t provide JSONP endpoints anyway. You need to handle the CORS issue differently - either proxy the request through your server or use Shopify’s proper authentication flow. Also, your URL construction looks problematic since you’re hardcoding placeholders that need actual values. For customer updates, consider using server-side requests instead of client-side Ajax to avoid exposing your API credentials in the browser.

hey there, looks like you’re mixing up your url placeholders - make sure you’re actually replacing {user_id} at the end with the real customer id, not just the userId variable. also shopify’s rest api doesnt support jsonp callbacks so that might be why you’re getting 404s when it tries to append the callback parameter.

I ran into something similar when I was working on a customer portal integration. The CORS issue you’re facing is actually a security feature working as intended - browsers won’t let you make direct API calls to external domains with credentials from client-side JavaScript. What worked for me was creating a server-side endpoint that acts as a proxy. Your backend receives the customer data, validates it, then makes the actual API call to Shopify using your private app credentials. This way you keep your API keys secure and avoid CORS entirely. Also worth checking that your API version is still supported - I had mysterious 404s once because the API version I was using got deprecated. Try switching to a newer version like 2023-04 or 2024-01 if you’re still having issues after fixing the CORS problem.