A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello,
i created a simple form that fetch customer first name, last name, email and phone number.
now I'm trying to do a script with API that allows users to change their name, email and number once clicking on the save button.
regarding the front-end and the interface.
this is the error im getting from the console:
"Access to XMLHttpRequest at 'https://{{api_key}}:{{api_password}}@{{store}}.myshopify.com/admin/api/2020-04/customers/{{customer_id}}.json' from origin 'https://sohaticare.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."
(I replaced the values with variable for security measures only, knowing that I placed the real values in the code)
and nothin was chaged.
as for my code :
let custFN = document.getElementById("customerFirstName").getAttribute("value") ;
let custLN = document.getElementById("customerLarstName").getAttribute("value") ;
let custEM = document.getElementById("customerEmail").getAttribute("value") ;
let custPH = document.getElementById("customerPhone").getAttribute("value") ;
var customerdata = {
"customer": {
"id": custFN ,
"first_name": custLN,
"last_name": custEM,
"email": custPH,
}
};
jQuery.ajax({
url: "https://{{api_key}}:{{api_password}}@{{store}}.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";
}
});
any idea ?