在Shopify上的Orders API中传递折扣代码

时间:2016-10-15 06:17:58

标签: rest post shopify

我一直在努力开发一款能够在不同渠道上接受Shopify订单的应用。我通过API成功下了订单,但我无法在订单中附上折扣代码。 POST数据的JSON对象如下:

{
  order: {
    email : request.params.order.email,    // string
    financial_status : 'pending',          // string
    send_receipt : true,                   // boolean 
    send_fulfillment_receipt : false,      // boolean
    note : request.params.order.note,      // string

    discount_codes : [], // supposed to be an array of Object| Problem here,

    line_items : request.params.order.line_items, // array
    customer : request.params.customer,    // JSON object 
    billing_address : request.params.order.billing_address,    // JSON object
    shipping_address : request.params.order.shipping_address   // JSON object
  }
}

根据文档, discount_codes 就是这样 -

Applicable discount codes that can be applied to the order. If no codes exist the value will default to blank. A Discount code will include the following fields: 

amount: The amount of the discount.
code: The discount code.
type: The type of discount. Can be one of : "percentage", "shipping", "fixed_amount" (default).

我做错了什么?我的discount_codes就是这个

[{amount: 100,code:'WELCOME10',type:'percentage'}]

以前有人这样做过吗?

4 个答案:

答案 0 :(得分:0)

我成功创建了一直有折扣的订单,没有ShopifyPlus,因为这是无关紧要的。适合我的数据结构如下所示:

 [ { "code": "Shop By PizzleFuzzle 10%", amount: "10", "type": "percentage" } ]

答案 1 :(得分:0)

根据此response from Shopify,只有在您同时传递total_discounts字段以及您要应用的折扣总额的情况下,您才能尝试执行的操作。

正如您在其他answer中所看到的那样,通过Shopify创建的任何代码都无法与API一起使用,并且不会记录其使用情况。

我试图使用此API来测试我生成的不同优惠券代码的应用程序,但这似乎是不可能的。显然,该API旨在应用自定义折扣,而不是Shopify中已经存在的折扣。这对我来说是一个令人沮丧的限制。

答案 2 :(得分:-1)

折扣对象仅适用于Shopify Plus商家。

一旦您成为Shopify Plus商家,您就可以创建折扣码:

POST /admin/discounts.json
{
  "discount": {
    "discount_type": "percentage",
    "value": "15.0",
    "code": "balderdash"
  }
}

请在Shopify API的折扣对象中查看更详细的文档:https://help.shopify.com/api/reference/discount

答案 3 :(得分:-1)

您应该使用value属性名称而不是amount属性名称。

e.g。

{value: 100,code:'WELCOME10',type:'percentage'}

而不是

{amount: 100,code:'WELCOME10',type:'percentage'}