skip to Main Content

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);
    }
});

3

Answers


  1. Chosen as BEST 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,


  2. I think you didn’t need to use JSON.stringify

    send data like an object

    $.ajax({
        type: "POST",
        url: "https://secret:[email protected]/admin/customers/1569902297146.json",
        contentType: 'application/json',
        data: {
           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);
        }
    });
    
    Login or Signup to reply.
  3. You are doing it all wrong. If you continue to expose your password on the front-end like that, you will quickly find someone will use it to turn all your Customers into porn star names with the result that you will lose your job, and your credibility. Instead, you use the App Proxy built into your private App to do non-CORS, safe, secure callbacks, without the password being involved.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search