API or method to update customer EMAIL address

Solved

API or method to update customer EMAIL address

PonMaheswaran
Shopify Partner
29 4 5

Dear all,

I am new to this shopify environment.

Right now we are working for my new client. I have following clarification.

1. The registered customer(Logged in user) need to update their email address. So that, next time he should login with updated mail address.  Is it possible to do in Shopify env. And if yes, How to achieve this with Shopify API. If possible please show some sample code also appreciable.

 

2. I need to add EMAIL MAGAZINE's SUBSCRIPTION/UNSUBSCRIPTION  as radio button type.  How to do this  using shopify API. Is it possible to do? If yes, please let me know the API if you aware.

 

3. Agree "TERMS & CONDITION" to be added as "checkbox" and to be SAVED while update the account details.

Is there any special API for this? if yes please let me know

 

Thanks in advance.

 

Regards,

Pon maheswaran K

Accepted Solution (1)
PonMaheswaran
Shopify Partner
29 4 5

This is an accepted solution.

Dear @kamilski81 ,

yes. it can be updated using following API.

https://shopify.dev/docs/admin-api/rest/reference/customers/customer?api[version]=2020-04#update-202...

Procedure as follows.

Goto your Shopify store Admin.

There is a "Apps" option at left side(https://famzon-development.myshopify.com/admin/apps)

Click on "Apps" and it will open the respective things at right side.

 

In right side find "Manage private apps" Hyper link.

On click of that, will open "Private apps" screen in which you can find "Create new private app" button.

Now click on "Create new private app" button and create the new private APP and get API key and password.

And below of "API key" and "Password" field, you can find "ADMIN API PERMISSIONS" heading.

provide "read and Write" permission for "Customers". and save that App.

 

Now copy that "Example URL" provided below that Password field. And append Email update API as follows.( In API_KEY and PASSWORD, replace with your private app's credentials)

https://{API_KEY}:{PASSWORD}@famzon-development.myshopify.com/admin/api/2020-04/customers/"+{{customer.id}}+".json

 

Now using this API, make your AJAX call as follows to update email ID or any other customer information like first name, last name, password etc..

   
var  customerdata = {
          "customer": {
            "id": {{customer.id}} ,
            "first_name": address_first_name,
            "last_name": address_last_name,
            "email": email,
            "password": password,
            "password_confirmation": cust_pswd_confirmation
             }
      };

 

In above JSON data,  "id": {{customer.id}}  is mandatory. Because, the information you are updating based on each user(Customer). So inputting customer ID is mandatory.

jQuery.ajax({
url: "https://API_KEY:PASSWORD@famzon-dev-msc.myshopify.com/admin/api/2020-04/customers/"+{{customer.id}}+".json",
type: "PUT",
data: customerdata,
dataType: "json",
beforeSend: function(x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
success: function(result) {
window.location.href = "/account/logout";
}
}); 

If this AJAX call return success result, then your customer info could have been updated successfully.

 

Regards,

Pon.

View solution in original post

Replies 9 (9)

PonMaheswaran
Shopify Partner
29 4 5

Dear all,

Please let me know, why my question has not been answered yet?

Is it  irrelevant to this forum or something else.?

 

Please let me know. If you answer me, then i could correct myself move forward to use/Not use this shopify.

 

 

Thanks & Regards,

Pon maheswaran K

kamilski81
Shopify Partner
5 0 3

Did you end up finding out whether a customer can update their email on the Shopify site?

PonMaheswaran
Shopify Partner
29 4 5

This is an accepted solution.

Dear @kamilski81 ,

yes. it can be updated using following API.

https://shopify.dev/docs/admin-api/rest/reference/customers/customer?api[version]=2020-04#update-202...

Procedure as follows.

Goto your Shopify store Admin.

There is a "Apps" option at left side(https://famzon-development.myshopify.com/admin/apps)

Click on "Apps" and it will open the respective things at right side.

 

In right side find "Manage private apps" Hyper link.

On click of that, will open "Private apps" screen in which you can find "Create new private app" button.

Now click on "Create new private app" button and create the new private APP and get API key and password.

And below of "API key" and "Password" field, you can find "ADMIN API PERMISSIONS" heading.

provide "read and Write" permission for "Customers". and save that App.

 

Now copy that "Example URL" provided below that Password field. And append Email update API as follows.( In API_KEY and PASSWORD, replace with your private app's credentials)

https://{API_KEY}:{PASSWORD}@famzon-development.myshopify.com/admin/api/2020-04/customers/"+{{customer.id}}+".json

 

Now using this API, make your AJAX call as follows to update email ID or any other customer information like first name, last name, password etc..

   
var  customerdata = {
          "customer": {
            "id": {{customer.id}} ,
            "first_name": address_first_name,
            "last_name": address_last_name,
            "email": email,
            "password": password,
            "password_confirmation": cust_pswd_confirmation
             }
      };

 

In above JSON data,  "id": {{customer.id}}  is mandatory. Because, the information you are updating based on each user(Customer). So inputting customer ID is mandatory.

jQuery.ajax({
url: "https://API_KEY:PASSWORD@famzon-dev-msc.myshopify.com/admin/api/2020-04/customers/"+{{customer.id}}+".json",
type: "PUT",
data: customerdata,
dataType: "json",
beforeSend: function(x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
success: function(result) {
window.location.href = "/account/logout";
}
}); 

If this AJAX call return success result, then your customer info could have been updated successfully.

 

Regards,

Pon.

PonMaheswaran
Shopify Partner
29 4 5

Dear @kamilski81 

Did you try this approach? If it works, then please accept this as solution.

 

Thanks & regards,

Pon maheswaran K

kamilski81
Shopify Partner
5 0 3

Thank you. This is not my question to accept as an answer. This solution looks good but I haven't tried it yet cause we went in a different direction for our business.

sirius7src
Visitor
1 0 0

Hi Pon!

I tried with your solution but I encountered a cors error like this.

sirius7src_0-1616886057555.png

How can I solve this problem?

If you have a solution to solve this problem, please let me know.

Thanks

Regards

AL33
Shopify Partner
43 0 3

How do you fix the cors problem, I met too.

PonMaheswaran
Shopify Partner
29 4 5

Dear @kamilski81 ,

I already have posted my answer here. It got deleted. I dont know the reason.

For your question, the answer is, i have fixed this issue by using following API.

https://shopify.dev/docs/admin-api/rest/reference/customers/customer?api[version]=2020-04#update-202...

For this to work, you need to create New Private APP in "Apps" section and get API key and password. After that using that info you could update the field(Email, First name, last name, password etc..) what you need.

 

Regards,

Pon.

 

Gordon_Chan
Shopify Partner
29 2 23

Although the spoken API is the way to go for, the API key & Password shouldn't be exposed in client side. Instead, client side makes a web form and make a post request with sufficient customer id and certain hashed value to act as authentication, so then the private app in the server side validate such form submit is authenticated and valid for a profile update, and then process the spoken API call from the server side to get rid of the CORS (cross-origin resource sharing) security rule.

 

The API credential should never expose in client side.

http://gordon-chan.net
I am a Freelance Web Engineer. Dedicated my life to e-commerce development.