What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Orders API - Adding Line Item Discounts

Orders API - Adding Line Item Discounts

Chris156
Shopify Partner
11 0 7

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.

 

Replies 8 (8)

Chris156
Shopify Partner
11 0 7

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

Caspar_Oreskov
Visitor
2 0 4

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?

Chris156
Shopify Partner
11 0 7

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.

 

 

Caspar_Oreskov
Visitor
2 0 4

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.

olance
Shopify Partner
6 0 4

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 😕

 

 

SunrseIntegratn
Shopify Partner
38 3 9

Encountering the same bug in Shopify's line item discounts not working as intended when creating orders through the API. When using a discount code that should be applied to a specific line item it gets applied to the order total.

Shopify integration, API, and software development for enterprises - https://www.sunriseintegration.com
itsdarrylnorris
Shopify Partner
7 0 9

I am running into the same issue. I have a discount that should be applied at the line item level and it's not having any impact on line item price. For this reason, the Shopify product reports will show up the prices as full price instead of the discounted price.

 

 

ggorman
Visitor
1 0 6

We have been experiencing this same issue since we moved onto shopify in 2018. To date there has been no resolution and we've only been told that "a feature request has been entered with the development team". That was in December of 2020. We've received no follow up from the development team since that reply. 

We've managed to make due with the issue up until Shopify's recent release where they are now displaying discounts on a line item level in shopify admin. This display is broken and not showing the correct amounts that were actually applied to the order (you can confirm this by viewing a customer's order confirmation page vs the same order in shopify admin). This display change has greatly exacerbated the issue and is causing extreme pain for our customer service team and their ability to tell the customer what they paid per line item. 

We, along with many other merchants, need a fix for this. 

Greyson Gorman