I've been trying without success to validate the email from my website against the MAGENTO customers API and throw a message (exist or not exist)
I mean, i have a website where customers are created; an email is given for every customer (The email is the primary key of every customer in MAGENTO) and everytime the customer is created in my website it is created in MAGENTO (using a middleware) too. The problem is that sometimes when a new customer is created in my website when it tries to create the customer in MAGENTO it throws an error message saying that the customer email already exist so i want to validate if the email exist or not in MAGENTO.
A few years ago i wrote this code and it validates whether the email exist or not but it is not using a MAGENTO API
Take a look:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<h2 style="color.darkgrey">Email validator </h2><br/>
<i id="status" class="" style="font-size:35px;color:green;display:inline-block;margin-left:5px;vertical-align:-5px;" ><i/>
<input id="email" type="email" class="form-control" style="display:inlane-block;width:300px;" />
<button id="btn" class="btn btn-success">Validate</button>
</body>
<script type="text/javascript">
$("#btn").click(function (){
check();
});
$("#email").change(function (){
check();
});
</body>
<script type="text/javascript">
var restURL= "http://apilayer.net/api/check?access_key=c5118f1f9827f42a5fc4b231932130a8&email="+$("#email").val()+"&smtp=1&format=1"
$.ajax({
type: 'GET',
url: restURL,
dataType:"json",
success: renderList,
});
return false;
});
function renderList(data)
{
if((data.format_valid==true)&&(data.smtp_check==true))
{
$('#status').removeClass('fa fa-check-circle-o').addClass('fa fa-check-circle-o').css("color","green");
}
else
{
$('#status').removeClass('fa fa-check-circle-o').addClass('fa fa-check-circle-o').css("color","green");
}
}
</script>
</html>
This is my MAGENTO API, take a look at this:
This is an example of the JSON i got from MAGENTO when i click on "SEND" on POSTMAN:
{
"magento_id": "54678",
"firstname": "Richard",
"lastname": "Herther",
"email": "[email protected]",
"password": null,
"website_id": "8",
"group_id": "7",
"disable_auto_group_change": "0",
"prefix": null,
"middlename": null,
"suffix": null,
"taxvat": null,
"account_id": [
"785784"
],
"document": "66958746845",
"document_type": "15",
"gender": null,
"telephone": null
},
This is a brief explanation:
Could you please help me to solve this? I need to modify my code a little bit in order to use the MAGENTO API but i dont know how to do it.
Can you help me?
EDIT:
I know it is possible to use MAGENTO REST API through JAVASCRIPT (calling magento's xmlrpc apis) but it is not working for me.
Take a look at this:
$.xmlrpc({
url: 'Your_magento_root/index.php/api/xmlrpc',
methodName: 'login',
params: ['my_username', "my_password"],
success: function(response, status, jqXHR) {
alert('Sucsses');
Session = response[0];
},
error: function(jqXHR, status, error) {
alert('error');
console.log(status);
}
});
and
$.xmlrpc({
url: 'Your_magento_root/index.php/api/xmlrpc',
methodName: 'call',
params: [Session, 'Your_methode_name',[0,'any other parameter',1]],
success: function(response, status, jqXHR) {
alert('Sucsses');
var data = response[0];
},
error: function(jqXHR, status, error) {
alert('error-inside');
console.log(error);
}
});
But this is not working properly
Is it okay? what am i doing wrong?
Could you please help me to modify my html code in order to use MAGENTO REST API through JAVASCRIPT?