Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

Re: discount code at line level- how to identify discount code for each line item in shopify order a

discount code at line level- how to identify discount code for each line item in shopify order api

MayurDhumal
Shopify Partner
7 0 1
am writing to you regarding our query for discount codes  identifier in Shopify order upon codes(product discounts two for each product, order discount and free shipping). 
we tried to find out the discount code identifier in response for each line item but there is no discount code present.
Please guide us how we identify all the discount codes for each line item.
I attached sample order payload response for your reference. 
 
Json for your reference attached in email. 

{
"orders": [
{
"id": 5861783863501,
"admin_graphql_api_id": "gid://shopify/Order/5861783863501",
"app_id": 580111,
"browser_ip": "27.107.164.66",
"buyer_accepts_marketing": true,
"cancel_reason": null,
"cancelled_at": null,
"cart_token": "c1-386a91f3c3b0c04127904194d33ad697",
"checkout_id": 46990111015117,
"checkout_token": "5f819d2d70cef908384adc1eb9741984",
"client_details": {
"accept_language": "en-IN",
"browser_height": null,
"browser_ip": "27.107.164.66",
"browser_width": null,
"session_hash": null,
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
},
"closed_at": null,
"confirmation_number": "HW7N3UV1H",
"confirmed": true,
"contact_email": "meherprasad.palaskar@etpgroup.com",
"created_at": "2024-02-14T18:47:37+05:30",
"currency": "INR",
"current_subtotal_price": "18500.00",
"current_subtotal_price_set": {
"shop_money": {
"amount": "18500.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "18500.00",
"currency_code": "INR"
}
},
"current_total_additional_fees_set": null,
"current_total_discounts": "1807.48",
"current_total_discounts_set": {
"shop_money": {
"amount": "1807.48",
"currency_code": "INR"
},
"presentment_money": {
"amount": "1807.48",
"currency_code": "INR"
}
},
"current_total_duties_set": null,
"current_total_price": "20350.00",
"current_total_price_set": {
"shop_money": {
"amount": "20350.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "20350.00",
"currency_code": "INR"
}
},
"current_total_tax": "1850.00",
"current_total_tax_set": {
"shop_money": {
"amount": "1850.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "1850.00",
"currency_code": "INR"
}
},
"customer_locale": "en-IN",
"device_id": null,
"discount_codes": [
{
"code": "MegaSale",
"amount": "1000.00",
"type": "fixed_amount"
},
{
"code": "SALE2024",
"amount": "400.00",
"type": "fixed_amount"
},
{
"code": "YrEndSale",
"amount": "100.00",
"type": "fixed_amount"
},
{
"code": "Freeship",
"amount": "307.48",
"type": "shipping"
}
],
"email": "meherprasad.palaskar@etpgroup.com",
"estimated_taxes": false,
"financial_status": "pending",
"fulfillment_status": null,
"landing_site": "/products/blue-t-shirt-round-neck-436",
"landing_site_ref": null,
"location_id": null,
"merchant_of_record_app_id": null,
"name": "6245",
"note": null,
"note_attributes": [],
"number": 5245,
"order_number": 6245,
"order_status_url": "https://sylphy.myshopify.com/58457620685/orders/5dec4a5288c7250b7cc80fa4d2604d1e/authenticate?key=db...",
"original_total_additional_fees_set": null,
"original_total_duties_set": null,
"payment_gateway_names": [
"Cash on Delivery (COD)"
],
"phone": null,
"po_number": null,
"presentment_currency": "INR",
"processed_at": "2024-02-14T18:47:36+05:30",
"reference": "52331bbec573d8c4390a8baaa9de966e",
"referring_site": "",
"source_identifier": "52331bbec573d8c4390a8baaa9de966e",
"source_name": "web",
"source_url": null,
"subtotal_price": "18500.00",
"subtotal_price_set": {
"shop_money": {
"amount": "18500.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "18500.00",
"currency_code": "INR"
}
},
"tags": "",
"tax_exempt": false,
"tax_lines": [
{
"price": "1850.00",
"rate": 0.1,
"title": "GST",
"price_set": {
"shop_money": {
"amount": "1850.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "1850.00",
"currency_code": "INR"
}
},
"channel_liable": false
}
],
"taxes_included": false,
"test": false,
"token": "5dec4a5288c7250b7cc80fa4d2604d1e",
"total_discounts": "1807.48",
"total_discounts_set": {
"shop_money": {
"amount": "1807.48",
"currency_code": "INR"
},
"presentment_money": {
"amount": "1807.48",
"currency_code": "INR"
}
},
"total_line_items_price": "20000.00",
"total_line_items_price_set": {
"shop_money": {
"amount": "20000.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "20000.00",
"currency_code": "INR"
}
},
"total_outstanding": "20350.00",
"total_price": "20350.00",
"total_price_set": {
"shop_money": {
"amount": "20350.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "20350.00",
"currency_code": "INR"
}
},
"total_shipping_price_set": {
"shop_money": {
"amount": "307.48",
"currency_code": "INR"
},
"presentment_money": {
"amount": "307.48",
"currency_code": "INR"
}
},
"total_tax": "1850.00",
"total_tax_set": {
"shop_money": {
"amount": "1850.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "1850.00",
"currency_code": "INR"
}
},
"total_tip_received": "0.00",
"total_weight": 640,
"updated_at": "2024-02-14T18:47:38+05:30",
"user_id": null,
"billing_address": {
"first_name": "Meher",
"address1": "Ion Orchand",
"phone": null,
"city": "Singapore",
"zip": "400023",
"province": null,
"country": "Singapore",
"last_name": "Palaskar",
"address2": "1floor101, Singapore",
"company": "ETP",
"latitude": null,
"longitude": null,
"name": "Meher Palaskar",
"country_code": "SG",
"province_code": null
},
"customer": {
"id": 5198684258509,
"email": "meherprasad.palaskar@etpgroup.com",
"created_at": "2021-09-20T11:32:50+05:30",
"updated_at": "2024-02-15T11:09:20+05:30",
"first_name": "Meher",
"last_name": "Palaskar",
"state": "enabled",
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": null,
"email_marketing_consent": {
"state": "subscribed",
"opt_in_level": "single_opt_in",
"consent_updated_at": "2023-12-06T17:02:46+05:30"
},
"sms_marketing_consent": null,
"tags": "",
"currency": "INR",
"tax_exemptions": [],
"admin_graphql_api_id": "gid://shopify/Customer/5198684258509",
"default_address": {
"id": 7058644697293,
"customer_id": 5198684258509,
"first_name": "Meher",
"last_name": "Palaskar",
"company": "ETP",
"address1": "Ion Orchand",
"address2": "1floor101, Singapore",
"city": "Singapore",
"province": null,
"country": "Singapore",
"zip": "400023",
"phone": "",
"name": "Meher Palaskar",
"province_code": null,
"country_code": "SG",
"country_name": "Singapore",
"default": true
}
},
"discount_applications": [
{
"target_type": "line_item",
"type": "discount_code",
"value": "500.0",
"value_type": "fixed_amount",
"allocation_method": "each",
"target_selection": "entitled",
"code": "MegaSale"
},
{
"target_type": "line_item",
"type": "discount_code",
"value": "200.0",
"value_type": "fixed_amount",
"allocation_method": "each",
"target_selection": "entitled",
"code": "SALE2024"
},
{
"target_type": "line_item",
"type": "discount_code",
"value": "100.0",
"value_type": "fixed_amount",
"allocation_method": "across",
"target_selection": "all",
"code": "YrEndSale"
},
{
"target_type": "shipping_line",
"type": "discount_code",
"value": "100.0",
"value_type": "percentage",
"allocation_method": "each",
"target_selection": "all",
"code": "Freeship"
}
],
"fulfillments": [],
"line_items": [
{
"id": 15009496826061,
"admin_graphql_api_id": "gid://shopify/LineItem/15009496826061",
"current_quantity": 2,
"fulfillable_quantity": 2,
"fulfillment_service": "manual",
"fulfillment_status": null,
"gift_card": false,
"grams": 160,
"name": "White t shirts v neck 2",
"price": "4999.00",
"price_set": {
"shop_money": {
"amount": "4999.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "4999.00",
"currency_code": "INR"
}
},
"product_exists": true,
"product_id": 7172443406541,
"properties": [],
"quantity": 2,
"requires_shipping": true,
"sku": "AM1",
"taxable": true,
"title": "White t shirts v neck 2",
"total_discount": "0.00",
"total_discount_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "INR"
}
},
"variant_id": 41495285956813,
"variant_inventory_management": "shopify",
"variant_title": null,
"vendor": "No Brand",
"tax_lines": [
{
"channel_liable": false,
"price": "954.64",
"price_set": {
"shop_money": {
"amount": "954.64",
"currency_code": "INR"
},
"presentment_money": {
"amount": "954.64",
"currency_code": "INR"
}
},
"rate": 0.1,
"title": "GST"
}
],
"duties": [],
"discount_allocations": [
{
"amount": "400.00",
"amount_set": {
"shop_money": {
"amount": "400.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "400.00",
"currency_code": "INR"
}
},
"discount_application_index": 1
},
{
"amount": "51.61",
"amount_set": {
"shop_money": {
"amount": "51.61",
"currency_code": "INR"
},
"presentment_money": {
"amount": "51.61",
"currency_code": "INR"
}
},
"discount_application_index": 2
}
]
},
{
"id": 15009496858829,
"admin_graphql_api_id": "gid://shopify/LineItem/15009496858829",
"current_quantity": 2,
"fulfillable_quantity": 2,
"fulfillment_service": "manual",
"fulfillment_status": null,
"gift_card": false,
"grams": 160,
"name": "Blue t-shirt round neck 436",
"price": "5001.00",
"price_set": {
"shop_money": {
"amount": "5001.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "5001.00",
"currency_code": "INR"
}
},
"product_exists": true,
"product_id": 7246456848589,
"properties": [],
"quantity": 2,
"requires_shipping": true,
"sku": "AM2",
"taxable": true,
"title": "Blue t-shirt round neck 436",
"total_discount": "0.00",
"total_discount_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "INR"
}
},
"variant_id": 41707738202317,
"variant_inventory_management": "shopify",
"variant_title": null,
"vendor": "No Brand",
"tax_lines": [
{
"channel_liable": false,
"price": "895.36",
"price_set": {
"shop_money": {
"amount": "895.36",
"currency_code": "INR"
},
"presentment_money": {
"amount": "895.36",
"currency_code": "INR"
}
},
"rate": 0.1,
"title": "GST"
}
],
"duties": [],
"discount_allocations": [
{
"amount": "1000.00",
"amount_set": {
"shop_money": {
"amount": "1000.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "1000.00",
"currency_code": "INR"
}
},
"discount_application_index": 0
},
{
"amount": "48.39",
"amount_set": {
"shop_money": {
"amount": "48.39",
"currency_code": "INR"
},
"presentment_money": {
"amount": "48.39",
"currency_code": "INR"
}
},
"discount_application_index": 2
}
]
}
],
"payment_terms": null,
"refunds": [],
"shipping_address": {
"first_name": "Meher",
"address1": "Ion Orchand",
"phone": null,
"city": "Singapore",
"zip": "400023",
"province": null,
"country": "Singapore",
"last_name": "Palaskar",
"address2": "1floor101, Singapore",
"company": "ETP",
"latitude": 1.3242989,
"longitude": 103.9020479,
"name": "Meher Palaskar",
"country_code": "SG",
"province_code": null
},
"shipping_lines": [
{
"id": 4934964379853,
"carrier_identifier": "650f1a14fa979ec5c74d063e968411d4",
"code": "Standard",
"discounted_price": "307.48",
"discounted_price_set": {
"shop_money": {
"amount": "307.48",
"currency_code": "INR"
},
"presentment_money": {
"amount": "307.48",
"currency_code": "INR"
}
},
"phone": null,
"price": "307.48",
"price_set": {
"shop_money": {
"amount": "307.48",
"currency_code": "INR"
},
"presentment_money": {
"amount": "307.48",
"currency_code": "INR"
}
},
"requested_fulfillment_service_id": null,
"source": "shopify",
"title": "Standard",
"tax_lines": [],
"discount_allocations": [
{
"amount": "307.48",
"amount_set": {
"shop_money": {
"amount": "307.48",
"currency_code": "INR"
},
"presentment_money": {
"amount": "307.48",
"currency_code": "INR"
}
},
"discount_application_index": 3
}
]
}
]
}
]
}

Reply 1 (1)

Liam
Community Manager
3108 344 889

Hi MayurDhumal,

 

So is your issue that you're seeing discount codes returned for the order, but not the line items? I see the discounts here in the code you've shared:

 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog