weixin_33735676 2017-06-13 06:18 采纳率: 0%
浏览 198

创建订单shopify api ajax

How to create an order is specified here https://help.shopify.com/api/reference/order#create

It is necessary to create an order through ajax using ajax I created the app, took from it API key and API secret key

$( "#button" ).click(function() {
     $.ajax({
        headers: {
        'Content-Type': 'application/json'
        'Accept': 'application/json'
        },
            url: 'https://API key:API secret key@myshop1.myshopify.com/admin/orders.json',
            type: 'POST',
            dataType: 'json',
            data: JSON.stringify({
                  {
          "order": {
            "line_items": [
              {
            "variant_id": 447654529,
            "quantity": 1
              }
            ]
          }
        }
                }),

        success: function(data) { 
            console.log(data);
        }
        });
});

Where is my mistake?

  • 写回答

1条回答 默认 最新

  • 三生石@ 2017-06-13 06:54
    关注

    I think there is some error in order json sent as data, it should be as follows

    data: JSON.stringify({
              "order": {
                "line_items": [
                  {
                "variant_id": 447654529,
                "quantity": 1
                  }
                ]
              }
            })
    

    Secondly, I would like to add that its not feasible to create order through ajax call using api key and password. Since this jQuery code will be in readable format in front end and your store api key and password will be leaked and it can create threat for your store. I would recommended to use some server side language like Java or Php to manipulate with store using that api key and password.

    评论

报告相同问题?