How to update customer data using Customer API from Shopify?

Solved
sstefanm
Shopify Partner
11 3 7

Greetings, I have a problem I'm trying to update my customer's data at my Shopify store through API but I always get server error 303 and I don't know what is a problem, I use jQuery and jQuery cookie plugin. Can someone help me here is the code?

 

 

 

$(document).ready(function() {
var customer_id = parseInt($("#customer_id").val());

// If customer click update button to update profile of customer
$("#updateCustomerProfile").click(function(e){
e.preventDefault();

var firstName = $("#firstName").val();
var lastName = $("#lastName").val();
var email = $("#email").val();
var phone = $("#phone").val();

var customer_data = {
"customer": {
"id":customer_id,
"email":email,
"first_name":firstName,
"last_name":lastName,
"phone":phone
}
};

var customer_data_json = JSON.stringify(customer_data);

$.cookie("session", null);

$.ajax({
url:'https://creamyrad.myshopify.com/admin/api/2021-07/customers/'+customer_id+'.json',
type: 'PUT',
cache: false,
data: customer_data_json,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(response) {
console.log(response);
},
error: function(response) {
console.log("-------------------------------- <ERROR> --------------------------------");
console.log(response);
console.log("-------------------------------- </ERROR> --------------------------------");
}
});


});

});

 

Stefan Momcilovic
Accepted Solution (1)

Accepted Solutions
sstefanm
Shopify Partner
11 3 7

This is an accepted solution.

I found a solution

var customer_data = {
            "customer": { 
              "id":customer_id, 
              "first_name":firstName,
              "last_name":lastName, 
              "phone":phone 
            } 
          }


          $.cookie("session", null);

          $.ajax({
            url:'https://API:PASSWORD@creamyrad.myshopify.com/admin/api/2021-07/customers/'+customer_id+'.json',
            type: 'PUT',
            cache: false,
            data: customer_data,
            dataType: "json",
            crossDomain: true,
            success: function(response) {
              console.log(response);
            },
            error: function(response) {
              console.log("-------------------------------- <ERROR> --------------------------------");
              console.log(response);
              console.log("-------------------------------- </ERROR> --------------------------------");
            }
          });
Stefan Momcilovic

View solution in original post

Replies 5 (5)
sstefanm
Shopify Partner
11 3 7

Screenshot from 2021-08-06 12-02-39.png

 

Stefan Momcilovic
sstefanm
Shopify Partner
11 3 7

This is an accepted solution.

I found a solution

var customer_data = {
            "customer": { 
              "id":customer_id, 
              "first_name":firstName,
              "last_name":lastName, 
              "phone":phone 
            } 
          }


          $.cookie("session", null);

          $.ajax({
            url:'https://API:PASSWORD@creamyrad.myshopify.com/admin/api/2021-07/customers/'+customer_id+'.json',
            type: 'PUT',
            cache: false,
            data: customer_data,
            dataType: "json",
            crossDomain: true,
            success: function(response) {
              console.log(response);
            },
            error: function(response) {
              console.log("-------------------------------- <ERROR> --------------------------------");
              console.log(response);
              console.log("-------------------------------- </ERROR> --------------------------------");
            }
          });
Stefan Momcilovic
nikhil14
New Member
2 0 0

can you please share this edit profile code 

AnkitVyas
Shopify Partner
9 0 0

Thank you for sharing such useful information.

 

cache: false,
data: customer_data,
dataType: "json",
crossDomain: true,

There are the useful parameters to call admin api from frontend.

 

Appreciate!!! 

luuquangtinh97
Shopify Partner
8 1 2

Thanks for your solution.

By the way, how can I get API:PASSWORD ?

Do I should create a private app on my store?