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.

Shipping line coupon code application misbehave

Solved

Shipping line coupon code application misbehave

SagarOZiva
New Member
4 0 0

Hello Guys,

 

I am using REST Order API to create order with discount code, shipping line discount, applied. Order is placed fine but the discount is applied on line items and order is placed on 0 price.  Following is a request body,

{
    "order": {
        "billing_address": {
            "zip": "000000",
            "country": "India",
            "province": "maharashtra",
            "save_address": true,
            "city": "mumbai",
            "phone": "98XXXXXXXX",
            "accepts_marketing": true,
            "address1": "Dahahdasd asdknjbas asdlasd",
            "country_name": "India",
            "last_name": "LastName",
            "first_name": "FirstName",
            "email": "name@domain.in"
        },
        "shipping_address": {
            "zip": "000000",
            "country": "India",
            "province": "maharashtra",
            "save_address": true,
            "city": "mumbai",
            "phone": "98XXXXXXXX",
            "accepts_marketing": true,
            "address1": "Dahahdasd asdknjbas asdlasd",
            "country_name": "India",
            "last_name": "LastName",
            "first_name": "FirstName",
            "email": "name@domain.in"
        },
        "line_items": [
            {
                "variant_id": "3925186848XXXX",
                "quantity": 1,
                "price": 539
            },
            {
                "variant_id": "2005252571XXXX",
                "quantity": 1,
                "price": 1599
            }
        ],
        "phone": "98XXXXXXXX",
        "customer": {
            "id": 16739250XXXX,
            "accepts_marketing": false
        },
        "discount_codes": [
            {
                "code": "FREESHIPPING",
                "amount": 100,
                "type": "percentage"
            }
        ],
        "buyer_accepts_marketing": false,
        "send_receipt": true,
        "currency": "INR",
        "financial_status": "pending",
        "gateway": "Cash on Delivery (COD)",
        "payment_gateway_names": [
            "Cash on Delivery (COD)"
        ]
    }
}
Accepted Solution (1)
GrahamS
Shopify Staff (Retired)
193 37 55

This is an accepted solution.

Hello @SagarOZiva ,

My apologies - It looks like I cited the incorrect documentation when providing the parameter for a shipping discount. You'll need to follow this general outline:

"discount_codes": [
  {
    "code": "FREESHIP",
    "amount": "30.00",
    "type": "shipping"
  }
]

 

Worth noting is that the discount will only apply if the shipping line you add in your REST call is of equal or lesser value than what you have in the "amount" section of this discount code entry. I noticed in your previous call examples, you weren't including any shipping lines, so there wouldn't be a way for a shipping specific discount to apply. More information about adding shipping lines is available in the REST documentation HERE

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 7 (7)

GrahamS
Shopify Staff (Retired)
193 37 55

Hello @SagarOZiva ,

When adding a shipping discount via REST API, you need to specifically cite "shipping_line" as your target_type with the discount. This is the case even if you are specifically using a code that is already marked as being shipping-specific in your admin, as API-applied discounts do not utilize the parameters of any codes that share their name in the admin.

Best,

Graham

To learn more visit the Shopify Help Center or the Community Blog.

SagarOZiva
New Member
4 0 0

Hello GrahamS,

Thank you for the prompt reply.

I tried what you have suggested but still don't see any progress. Tried following json and still facing the issue,

{
    "order": {
        "billing_address": {
            "zip": "000000",
            "country": "India",
            "province": "maharashtra",
            "save_address": true,
            "city": "mumbai",
            "phone": "98XXXXXXXX",
            "accepts_marketing": true,
            "address1": "Dahahdasd asdknjbas asdlasd",
            "country_name": "India",
            "last_name": "LastName",
            "first_name": "FirstName",
            "email": "name@domain.in"
        },
        "shipping_address": {
            "zip": "000000",
            "country": "India",
            "province": "maharashtra",
            "save_address": true,
            "city": "mumbai",
            "phone": "98XXXXXXXX",
            "accepts_marketing": true,
            "address1": "Dahahdasd asdknjbas asdlasd",
            "country_name": "India",
            "last_name": "LastName",
            "first_name": "FirstName",
            "email": "name@domain.in"
        },
        "line_items": [
            {
                "variant_id": "3925186848XXXX",
                "quantity": 1,
                "price": 539
            },
            {
                "variant_id": "2005252571XXXX",
                "quantity": 1,
                "price": 1599
            }
        ],
        "phone": "98XXXXXXXX",
        "customer": {
            "id": 16739250XXXX,
            "accepts_marketing": false
        },
        "discount_codes": [
            {
                "code": "FREESHIPPING",
                "amount": 100,
                "type": "percentage",
                "target_type": "shipping_line"
            }
        ],
        "buyer_accepts_marketing": false,
        "send_receipt": true,
        "currency": "INR",
        "financial_status": "pending",
        "gateway": "Cash on Delivery (COD)",
        "payment_gateway_names": [
            "Cash on Delivery (COD)"
        ]
    }
}

Please help me understand what is wrong with the json. 

GrahamS
Shopify Staff (Retired)
193 37 55

Hello @SagarOZiva ,

Can you provide me with the payload response for when you call for the affected order over API? I'd like to see which specific fields are returning 0 after the order has been created. There are a few potential reasons why this might happening.

To learn more visit the Shopify Help Center or the Community Blog.

SagarOZiva
New Member
4 0 0

Hello GrahamS,

 

Here's the response payload for the order,

 

{
    "order": {
        "id": 395292XXXXXXX,
        "admin_graphql_api_id": "gid://shopify/Order/395292XXXXXXX",
        "app_id": 25439XX,
        "browser_ip": null,
        "buyer_accepts_marketing": false,
        "cancel_reason": null,
        "cancelled_at": null,
        "cart_token": null,
        "checkout_id": null,
        "checkout_token": null,
        "closed_at": null,
        "confirmed": true,
        "contact_email": "name@domain.in",
        "created_at": "2021-08-04T19:24:44+05:30",
        "currency": "INR",
        "current_subtotal_price": "0.00",
        "current_subtotal_price_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "INR"
            }
        },
        "current_total_discounts": "2138.00",
        "current_total_discounts_set": {
            "shop_money": {
                "amount": "2138.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "2138.00",
                "currency_code": "INR"
            }
        },
        "current_total_duties_set": null,
        "current_total_price": "100.00",
        "current_total_price_set": {
            "shop_money": {
                "amount": "100.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "100.00",
                "currency_code": "INR"
            }
        },
        "current_total_tax": "0.00",
        "current_total_tax_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "INR"
            }
        },
        "customer_locale": null,
        "device_id": null,
        "discount_codes": [
            {
                "code": "FREESHIPPING",
                "amount": "2138.00",
                "type": "percentage"
            }
        ],
        "email": "name@domain.in",
        "financial_status": "pending",
        "fulfillment_status": null,
        "gateway": "Cash on Delivery (COD)",
        "landing_site": null,
        "landing_site_ref": null,
        "location_id": null,
        "name": "#7157XX",
        "note": null,
        "note_attributes": [],
        "number": 7147XX,
        "order_number": 7157XX,
        "order_status_url": "https://www.oziva.in/23932XXX/orders/5XX73bb4a1b4df172e391ee8e237c340/authenticate?key=a69445ac6547667eef687462f27XXXXX",
        "original_total_duties_set": null,
        "payment_gateway_names": [],
        "phone": "+91XXXXXXXXXX",
        "presentment_currency": "INR",
        "processed_at": "2021-08-04T19:24:44+05:30",
        "processing_method": "",
        "reference": null,
        "referring_site": null,
        "source_identifier": null,
        "source_name": "2543XXX",
        "source_url": null,
        "subtotal_price": "0.00",
        "subtotal_price_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "INR"
            }
        },
        "tags": "",
        "tax_lines": [],
        "taxes_included": false,
        "test": false,
        "token": "58573bb4a1b4df172e391ee8e23XXXXX",
        "total_discounts": "2138.00",
        "total_discounts_set": {
            "shop_money": {
                "amount": "2138.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "2138.00",
                "currency_code": "INR"
            }
        },
        "total_line_items_price": "2138.00",
        "total_line_items_price_set": {
            "shop_money": {
                "amount": "2138.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "2138.00",
                "currency_code": "INR"
            }
        },
        "total_outstanding": "100.00",
        "total_price": "100.00",
        "total_price_set": {
            "shop_money": {
                "amount": "100.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "100.00",
                "currency_code": "INR"
            }
        },
        "total_price_usd": "1.35",
        "total_shipping_price_set": {
            "shop_money": {
                "amount": "100.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "100.00",
                "currency_code": "INR"
            }
        },
        "total_tax": "0.00",
        "total_tax_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "INR"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "INR"
            }
        },
        "total_tip_received": "0.00",
        "total_weight": 0,
        "updated_at": "2021-08-04T19:24:44+05:30",
        "user_id": null,
        "billing_address": {
            "first_name": "XXXXXXXXXX",
            "address1": "XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX",
            "phone": "XXXXXXXXXX",
            "city": "XXXXXXXXXX",
            "zip": "XXXXXXXXXX",
            "province": "Maharashtra",
            "country": "XXXXXXXXXX",
            "last_name": "XXXXXXXXXX",
            "address2": null,
            "company": null,
            "latitude": 19.052XXXX,
            "longitude": 72.90XXXXX,
            "name": "XXXXXXXXXX XXXXXXXXXX",
            "country_code": "IN",
            "province_code": "MH"
        },
        "customer": {
            "id": 16739XXXXXXX,
            "email": "name@domain.in",
            "accepts_marketing": false,
            "created_at": "2017-10-18T19:04:27+05:30",
            "updated_at": "2021-08-04T19:24:45+05:30",
            "first_name": "XXXXXXXXXX",
            "last_name": "XXXXXXXXXX",
            "orders_count": 225,
            "state": "enabled",
            "total_spent": "15004.00",
            "last_order_id": 39529229XXXXX,
            "note": null,
            "verified_email": true,
            "multipass_identifier": null,
            "tax_exempt": false,
            "phone": null,
            "tags": "",
            "last_order_name": "#7157XX",
            "currency": "INR",
            "accepts_marketing_updated_at": "2021-07-19T11:35:59+05:30",
            "marketing_opt_in_level": null,
            "tax_exemptions": [],
            "admin_graphql_api_id": "gid://shopify/Customer/167392XXXXXX",
            "default_address": {
                "id": 632638XXXXXXX,
                "customer_id": 16739XXXXXXX,
                "first_name": "XXXXXXXXXX",
                "last_name": "XXXXXXXXXX",
                "company": null,
                "address1": "XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX",
                "address2": null,
                "city": "XXXXXXXXXX",
                "province": "XXXXXXXXXX",
                "country": "India",
                "zip": "XXXXXXXXXX",
                "phone": "XXXXXXXXXX",
                "name": "XXXXXXXXXX XXXXXXXXXX",
                "province_code": "MH",
                "country_code": "IN",
                "country_name": "India",
                "default": true
            }
        },
        "discount_applications": [
            {
                "target_type": "line_item",
                "type": "manual",
                "value": "100.0",
                "value_type": "percentage",
                "allocation_method": "across",
                "target_selection": "all",
                "title": "FREESHIPPING",
                "description": "FREESHIPPING"
            }
        ],
        "fulfillments": [],
        "line_items": [
            {
                "id": 10634597XXXXXX,
                "admin_graphql_api_id": "gid://shopify/LineItem/10634597XXXXXX",
                "fulfillable_quantity": 1,
                "fulfillment_service": "manual",
                "fulfillment_status": null,
                "gift_card": false,
                "grams": 0,
                "name": "OZiva Bettr.C+ (Plant based Vitamin C with Zinc, Rosehip, Bioflavonoids) for Advanced Immunity, Better Absorption than Synthetic Vitamin C, 60 capsules - Bettr.C+ / Pack of 1 (60 N capsules)",
                "price": "539.00",
                "price_set": {
                    "shop_money": {
                        "amount": "539.00",
                        "currency_code": "INR"
                    },
                    "presentment_money": {
                        "amount": "539.00",
                        "currency_code": "INR"
                    }
                },
                "product_exists": true,
                "product_id": 6536812691515,
                "properties": [],
                "quantity": 1,
                "requires_shipping": true,
                "sku": "BC01XXXX",
                "taxable": false,
                "title": "OZiva Bettr.C+ (Plant based Vitamin C with Zinc, Rosehip, Bioflavonoids) for Advanced Immunity, Better Absorption than Synthetic Vitamin C, 60 capsules",
                "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": 39251868XXXXXX,
                "variant_inventory_management": "shopify",
                "variant_title": "Bettr.C+ / Pack of 1 (60 N capsules)",
                "vendor": "OZiva",
                "tax_lines": [],
                "duties": [],
                "discount_allocations": [
                    {
                        "amount": "539.00",
                        "amount_set": {
                            "shop_money": {
                                "amount": "539.00",
                                "currency_code": "INR"
                            },
                            "presentment_money": {
                                "amount": "539.00",
                                "currency_code": "INR"
                            }
                        },
                        "discount_application_index": 0
                    }
                ]
            },
            {
                "id": 1063459XXXXXXX,
                "admin_graphql_api_id": "gid://shopify/LineItem/1063459XXXXXXX",
                "fulfillable_quantity": 1,
                "fulfillment_service": "manual",
                "fulfillment_status": null,
                "gift_card": false,
                "grams": 0,
                "name": "OZiva Protein & Herbs, Men - Whey Protein with Herbs & Multivitamins - 500 g (16 Servings) / Chocolate",
                "price": "1599.00",
                "price_set": {
                    "shop_money": {
                        "amount": "1599.00",
                        "currency_code": "INR"
                    },
                    "presentment_money": {
                        "amount": "1599.00",
                        "currency_code": "INR"
                    }
                },
                "product_exists": true,
                "product_id": 204449XXXXXXX,
                "properties": [],
                "quantity": 1,
                "requires_shipping": true,
                "sku": "PH01CXXX",
                "taxable": false,
                "title": "OZiva Protein & Herbs, Men - Whey Protein with Herbs & Multivitamins",
                "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": 20052525XXXXX,
                "variant_inventory_management": "shopify",
                "variant_title": "500 g (16 Servings) / Chocolate",
                "vendor": "OZiva",
                "tax_lines": [],
                "duties": [],
                "discount_allocations": [
                    {
                        "amount": "1599.00",
                        "amount_set": {
                            "shop_money": {
                                "amount": "1599.00",
                                "currency_code": "INR"
                            },
                            "presentment_money": {
                                "amount": "1599.00",
                                "currency_code": "INR"
                            }
                        },
                        "discount_application_index": 0
                    }
                ]
            }
        ],
        "refunds": [],
        "shipping_address": {
            "first_name": "XXXXXXXXXX",
            "address1": "XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX",
            "phone": "XXXXXXXXXX",
            "city": "XXXXXXXXXX",
            "zip": "XXXXXXXXXX",
            "province": "Maharashtra",
            "country": "India",
            "last_name": "XXXXXXXXXX",
            "address2": null,
            "company": null,
            "latitude": 19.052XXXX,
            "longitude": 72.9XXXXXX,
            "name": "XXXXXXXXXX XXXXXXXXXX",
            "country_code": "IN",
            "province_code": "MH"
        },
        "shipping_lines": [
            {
                "id": 3368881XXXXXX,
                "carrier_identifier": null,
                "code": "standard",
                "delivery_category": null,
                "discounted_price": "100.00",
                "discounted_price_set": {
                    "shop_money": {
                        "amount": "100.00",
                        "currency_code": "INR"
                    },
                    "presentment_money": {
                        "amount": "100.00",
                        "currency_code": "INR"
                    }
                },
                "phone": null,
                "price": "100.00",
                "price_set": {
                    "shop_money": {
                        "amount": "100.00",
                        "currency_code": "INR"
                    },
                    "presentment_money": {
                        "amount": "100.00",
                        "currency_code": "INR"
                    }
                },
                "requested_fulfillment_service_id": null,
                "source": "shopify",
                "title": "standard",
                "tax_lines": [],
                "discount_allocations": []
            }
        ]
    }
}

 

I want discount to be applied, ie. discount code to be visible over order in dashboard. Not looking for manual discount

 

GrahamS
Shopify Staff (Retired)
193 37 55

This is an accepted solution.

Hello @SagarOZiva ,

My apologies - It looks like I cited the incorrect documentation when providing the parameter for a shipping discount. You'll need to follow this general outline:

"discount_codes": [
  {
    "code": "FREESHIP",
    "amount": "30.00",
    "type": "shipping"
  }
]

 

Worth noting is that the discount will only apply if the shipping line you add in your REST call is of equal or lesser value than what you have in the "amount" section of this discount code entry. I noticed in your previous call examples, you weren't including any shipping lines, so there wouldn't be a way for a shipping specific discount to apply. More information about adding shipping lines is available in the REST documentation HERE

To learn more visit the Shopify Help Center or the Community Blog.

SagarOZiva
New Member
4 0 0

Hello @GrahamS 

Thanks for the solution. This worked for me.

 

 

alexatedia
Visitor
1 0 0

great i was had the same problem, as a gift for you, you can use https://all3rood.com/ and find fordeal code copy it and save your money in the next time you shop from fodeal.