Ad

Customer Update Request Is Working Via POSTMAN But Not Via AJAX Using Shopify Private App

I am trying to update customer tag on Shopify by using its private app. I tried it with postman and everything is working fine but via AJAX, it takes me to success callback instead of error but in success I get auth link instead of customer record like I get in postman.

 $.ajax({
    type: "POST",
    url: "https://secret:[email protected]/admin/customers/1569902297146.json",
    contentType: 'application/json',
    data: JSON.stringify({
       customer: {
         id: "1569902297146",
         email: "[email protected]",
         tags: "loyalty-member"
       }
     }),
    success: function(msg, b ,b) {
        console.log(msg);
    },
    error: function(a, b, c) {
        console.log(msg);
    }
});
Ad

Answer

I did not find any productive answer/info over the internet. Finally, After hit and trial with AJAX I am able to get success result.

$.ajax({
    type: "POST",
    url: "https://secret:[email protected]/admin/customers/1569902297146.json",
    contentType: 'application/json',
    crossDomain: true,
    data: JSON.stringify({
       customer: {
         id: "1569902297146",
         email: "[email protected]",
         tags: "loyalty-member"
       }
     }),
    success: function(msg, b ,b) {
        console.log(msg);
    },
    error: function(a, b, c) {
        console.log(msg);
    }
});

The real hero is crossDomain. I don't know why Shoify do not allow its PUT and POST requests without making crossDomain: true,

Ad
source: stackoverflow.com
Ad