如何拨打shopify admin api表格Shopify商店页面

时间:2018-04-09 09:30:37

标签: jquery shopify shopify-app

如何从shopify商店调用“创建客户”管理员Api。当使用api admin / order.json调用GET方法时,它的工作原理。但是当我们调用post方法然后显示html json响应时,请“请登录shopify”。

请检查以下代码

<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>

2 个答案:

答案 0 :(得分:1)

登录您的shopify商店。打开控制台并输入此代码。

     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: "/admin/customers.json", success: function(result){
              console.log(result);             
        }});

此处不需要api密钥或密钥。因为您已使用您的用户名和密码登录。

答案 1 :(得分:1)

这听起来像是Shopify的GraphQL Storefront API的工作。您不应该尝试直接从客户端代码调用管理API。这不安全,因为管理员API访问令牌(以及私人应用程序中的密码)必须保密。