How to call “Create Customer” admin Api from shopify store . When call GET method with api admin/order.json then it’s works. But when we call post method then display html json response like “Please login to shopify”.
Please check following code
<script>
jQuery(document).ready(function(){
jQuery("button").click(function(){
var info = {
'customer': {
'first_name': 'Sw',
'last_name': 'Lastnameson',
'email': '[email protected]',
'phone': '+15142546011',
'verified_email': true,
'addresses': [{
'address1': '123 Oak St',
'city': 'Ottawa',
'province': 'ON',
'phone': '555-1212',
'zip': '123 ABC',
'last_name': 'Lastnameson',
'first_name': 'Mother',
'country': 'CA'
}]
}
};
jQuery.ajax({
type: "POST",
data:info,
url: "https://apikey:password@hostname/admin/customers.json", success: function(result){
console.log(result);
}});
});
});
</script>
2
Answers
Login to your shopify store. Open console and enter this code.
You do not need api key or secret key here. Because you are already login with your user name and password.
This sounds like a job for Shopify’s GraphQL Storefront API. You should not try to call the admin API directly from client side code. That would not be safe because admin API access tokens (and passwords in the case of private apps) must be kept secret.