How to call shopify admin api form Shopify store page

Highlighted
Tourist
16 0 1

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': 'steve.lastnameson@example.com',
        '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>

 

How post request work form shopify store . Please any one guide me. 

Thanks 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1555 81 287

Two things:

First: If you're posting with cookies, we redirect you to the HTML login flow.

Second: I hope you're not hardcoding your API credentials into that URL client-side. That's incredibly insecure.

I recommend deferring to an external app to make API requests by making a post request to your app server so your credentials are safe server-side.

0 Likes
Highlighted
Tourist
16 0 1

I am trying to update customer record using api request in javascript but it's not update record 

 

var data = {
                "customer": {
                  "id": 468737556539,
                  "email": "changed@email.address.com"
                  }
            }    
                
alert()                
$.ajax({
                 type: "PUT",  
                 url: "https://apikey:password@hostname.myshopify.com/admin/customers/468737556539.json", 
                 data: data,
                 success: function(result){
                        alert(result);
                        console.log(result);

                 }
                 });
                
                
});

 

please check 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1555 81 287

@abhijit:

Ca you clarify for me whether you're making this request from the client? It sounds to me like that's the case, where your credentials are exposed which is a security risk to merchants.

Additionally, it appears that your forum post signature also contains this URL. I sincerely hope those aren't current credentials.

Focus on that before worrying about the requests you're trying to make in general.

0 Likes
Highlighted
Tourist
16 0 1

Hi  Alex,

Ca you clarify for me whether you're making this request from the client? 

Answer : I am trying to from shopify store page. I have created one template in that template we have this above code. Next this template was assinged to  shopify  store page. 

 

 

0 Likes
Highlighted
Shopify Expert
10007 116 1818

It's a good thing those sort of requests are blocked given the security issue. Your change request will contain cookies, and Shopify will block that request because it does.

Even if it worked, any request (PUT/UPDATE/etc) should be going through an authenticated app and not via something where you're revealing the key details to the world.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
Highlighted
New Member
1 0 0

Hi there,

           I have created shopify app with react and node js and posted registration form HTML in  through script tag API to render in storefront 

I can able to trigger the click event in storefront.

can anyone explain me how to create a customer from the shopify app in detail 

Thanks

0 Likes