Orders API - Adding Line Item Discounts

Shopify Partner
11 0 0

Hello all.

 

I'm using the Shopify Orders API to create an order, which should have some line item discounts in them. I tried using the total_discount in a line item, and it does not work (is comes back as zero when the order is created). I then tried using the "discount_allocations"  in the line item (based on the appropriate discount_applications ) and same result ...

an example of the discount applications used in the JSON

"discount_applications": [
  {
    "type": "manual",
    "title": "Amazon DS",
    "description": "Amazon Direct Fulfilment",
    "value": "36.99",
    "value_type": "fixed_amount",
    "allocation_method": "one",
    "target_selection": "explicit",
    "target_type": "line_item"
    }
    ],

And the line item:

  "line_items" : [
  
    {
      "price" : "81",
      "quantity" : 1,
      "sku" : "106-02",
      "variant_id" : 4494565376011,
      "total_discount": "36.99",
      "discount_allocations": [
          {
            "amount": "36.99",
            "discount_application_index": 0
          }
        ]      
     }
  ],

Any insights as to what is the proper method? I just want to add the appropriate discount value so it shows up correctly in the reporting.

 

0 Likes
Shopify Partner
11 0 0

Any insights? I really need help in getting this to work :-S

0 Likes
New Member
2 0 0

We are having some issues with entitled products, but if you wish to apply a discount to an order, you will need to add the discountcode to the request: 

{ 
  "order": { 
    "discount_codes": [
      {
        "code": "PERCENTAGE_ENTITLED_EACH",
      }
    ]
  }
}

We have not found a way to set discount_applications for either order or line_items, since they (1) gets ignored if no discount code is added and (2) discount_applications are overridden by discountcode.

 

When using discountcodes with entitled products, it does not work as expected. First of all the discount is applied to the whole order, instead of on itemlevel and secondly, the total price differs a bit.

 

The result when going through checkout, is the following: (cleaned to present only discount-related fields):

{
  "order": {
    "discount_applications": [
      {
        "type": "discount_code",
        "value": "10.0",
        "value_type": "percentage",
        "allocation_method": "each",
        "target_selection": "entitled",
        "target_type": "line_item",
        "code": "PERCENTAGE_ENTITLED_EACH"
      }
    ],
    "discount_codes": [
      {
        "code": "PERCENTAGE_ENTITLED_EACH",
        "amount": "1.20",
        "type": "percentage"
      }
    ],
    "line_items": [
      {
        "name": "Product 1 - 2",
        "discount_allocations": [],
      },
      {
        "name": "Copy of Product 2 - 1",
        "discount_allocations": [
          {
            "amount": "1.20",
            "discount_application_index": 0
          }
        ]
      }
    ]
  }
}

 

When discount is applied through API, it does a bit of magic, and applies the discountcode across the order: 

 

{
  "order": {
    "discount_applications": [
      {
        "type": "discount_code",
        "value": "1.2",
        "value_type": "percentage",
        "allocation_method": "across",
        "target_selection": "all",
        "target_type": "line_item",
        "code": "PERCENTAGE_ENTITLED_EACH"
      }
    ],
    "discount_codes": [
      {
        "code": "PERCENTAGE_ENTITLED_EACH",
        "amount": "1.45",
        "type": "percentage"
      }
    ],
    "line_items": [
      {
        "name": "Product 1 - 2",
        "discount_allocations": [
          {
            "amount": "1.31",
            "discount_application_index": 0
          }
        ]
      },
      {
        "name": "Copy of Product 2 - 1",
        "discount_allocations": [
          {
            "amount": "0.14",
            "discount_application_index": 0
          }
        ]
      }
    ]
  }
}

 

Notice the difference in discount_applications on the orderlevel. For some reason, Shopify does only allow discounts that are across/all, and then does some "magic" to recalculate the discount.

 

Is there anyone from Shopify that are able to explain the implementation and how to get around it?

0 Likes
Shopify Partner
11 0 0

I got a reply on another post indicating that discount allocations and discount applications are read-only via the API, which means you cannot use them when creating orders via the API.  It is quite confusing since Shopify API documentation does not clearly indicate what can be used or not when creating orders.

 

 

0 Likes
New Member
2 0 0

I think I read the same one at a certain point, but this still means, that only discounts for the whole order, will work consistently, when creating orders through the API. Discounts for specific products, should not be used at this point.

It is a major issue for us at this point, so I hope someone has a solution for this.

0 Likes
Highlighted
New Member
2 0 0

I'd like to bump this thread up, as I have reached the same conclusions on my side and I'd really like some pointers from the Shopify team if that's at all possible...

 

I don't understand the point of providing an API, if it doesn't allow us to reproduce what the underlying system is capable of doing :\

 

 

0 Likes