Apply code to cart
The shopping cart API is used for the shopping cart interaction generated by the customer during the session. When a code needs to be added to the shopping cart, the corresponding operation can be completed by requesting this interface.
Request information
API Path:
POST https://{handle}.myshopline.com/cart/discount-code/apply
Request header:
| Parameter name | Parameter type | Required | Array or not | Default value | describe |
|---|---|---|---|---|---|
| Content-Type | String | Y | N | application/json | |
| cookie | String | Y | N | SHOPLINE cookie |
request body:
| Parameter name | Parameter name | Parameter type | Required | Array or not | Example | describe |
|---|---|---|---|---|---|---|
| code | Object | Y | N | Shopping cart code |
Response information
Response body:
| Parameter name | Parameter name | Parameter name | Parameter name | Parameter type | Array or not | Example | describe |
|---|---|---|---|---|---|---|---|
| items | Object | Y | Shopping cart item list | ||||
| id | String | N | 36110175633573 | The unique identification of the product is SKU_ id | |||
| group_id | String | N | 0 | Item group ID | |||
| quantity | Integer | N | 2 | Quantity of goods | |||
| properties | Long | N | ![]() | ||||
| variant_id | String | N | 36110175633573 | Item SKU_ id | |||
| title | String | N | test1 | Product title + SKU title name + specification | |||
| price | Double | N | 200 | Commodity price | |||
| original_price | Double | N | 200 | Original price of goods (may be 0) | |||
| discounted_price | Double | N | 200 | Price after discount | |||
| line_price | Double | N | 200 | Commodity line selling price | |||
| original_line_price | Double | N | 200 | Original price of commodity line (may be 0) | |||
| total_discount | Double | N | 200 | Total discount amount of a single item | |||
| discounts | Object | Y | Discount of commodity bank | ||||
| amount | Double | N | 200 | Preferential amount | |||
| title | String | N | 50 minus 100 | Preferential name | |||
| sku | String | N | Red XL | Item SKU_ id | |||
| grams | String | N | 100 | Commodity weight unit: G | |||
| taxable | Boolean | N | true | Whether to collect tax | |||
| product_id | String | N | 36110175633573 | Commodity SPU_ id | |||
| gift_card | Boolean | N | true | Is it a gift card product | |||
| final_price | Double | N | 500 | Amount of goods involved in pricing | |||
| final_line_price | Double | N | 500 | Amount of commodity line participating in pricing | |||
| url | String | N | https://ddfasdfasdf | Commodity master link | |||
| featured_image | String | N | |||||
| aspectRatio | Double | N | Aspect ratio | ||||
| alt | String | N | Mouse over prompt | ||||
| height | Integer | N | Display height | ||||
| url | String | N | picture | ||||
| width | Integer | N | Display width | ||||
| image | String | N | Product image | ||||
| handle | String | N | Product handle | ||||
| requires_shipping | String | N | Whether shipment is required | ||||
| product_title | String | N | Product title | ||||
| variant_title | String | N | Splicing of all specifications | ||||
| variant_options | String | N | Enumeration of all specifications | ||||
| options_with_values | String | N | Specifications | ||||
| name | String | N | Specifications name | ||||
| value | String | N | Specifications value | ||||
| line_level_discount_allocations | String | N | Discount of commodity bank information | ||||
| amount | Double | N | Preferential amount | ||||
| discountApplication | String | N | |||||
| type | Integer | N | |||||
| title | String | N | Preferential name | ||||
| description | String | N | Offer describe | ||||
| value | Double | N | Preferential amount | ||||
| created_at | String | N | Activity creation time | ||||
| value_type | String | N | Discount activity type: | ||||
| target_type | String | N | |||||
| code | String | N | code | ||||
| status | String | N | status enable unable | ||||
| line_level_total_discount | Double | N | Total amount of commodity bank |
Request and response example
Scenario 1: Update the shopping cart code normally
{
"token":"14f1ad57a80c49458f73154199e4e03a",
"note":"",
"attributes":{
},
"items":[
{
"id":"18056883180998219714141560",
"properties":null,
"quantity":1,
"title":"RetroLife HQKZ-006 High Fidelity Bluetooth Turntable For Vinyl Music System Brown",
"price":199.99,
"discounts":[
{
"amount":18,
"title":"Subscribe for $18 off"
}
],
"sku":"HQKZ-006 Brown",
"grams":"7.0",
"taxable":true,
"url":"https://boxlegend.myshopline.com/products/high-fidelity-turntable-with-moving-magnetic-cartridge-hqkz-006",
"image":"https://img-va.myshopline.com/image/store/2000056861/1620894872993/0365f2957d7148809637bbc993a5b9d1.jpeg?w=1500&h=1460",
"handle":"high-fidelity-turntable-with-moving-magnetic-cartridge-hqkz-006",
"key":"18056883180998219714141560:5f55c13faf9d4d889294f7a8cd7a5379",
"urlToRemove":"/cart/change?id=18056883180998219714141560:5f55c13faf9d4d889294f7a8cd7a5379&quantity=0",
"group_id":"0",
"variant_id":"18056883180998219714141560",
"product_custom_type":"",
"original_price":229.99,
"discounted_price":181.99,
"line_price":199.99,
"original_line_price":229.99,
"total_discount":18,
"product_id":"16052923505799594374111560",
"gift_card":false,
"final_price":181.99,
"final_line_price":181.99,
"featured_image":{
"alt":null,
"height":null,
"url":"https://img-va.myshopline.com/image/store/2000056861/1620894872993/0365f2957d7148809637bbc993a5b9d1.jpeg?w=1500&h=1460",
"width":null,
"aspect_ratio":null
},
"requires_shipping":true,
"product_title":"RetroLife HQKZ-006 High Fidelity Bluetooth Turntable For Vinyl Music System",
"variant_title":"Brown",
"variant_options":[
"Brown"
],
"options_with_values":[
{
"name":"Model",
"value":"Brown"
}
],
"line_level_discount_allocations":[
{
"amount":18,
"discount_application":{
"type":3,
"title":"Subscribe for $18 off",
"description":null,
"value":18,
"code":"RTL18",
"status":"enable",
"created_at":null,
"value_type":"fix_amount",
"target_type":"line_item"
}
}
],
"line_level_total_discount":18,
"product_source":1,
"selling_plan_allocation":null,
"enable_quantity_adjust":true,
"enable_delete":true
}
],
"currency":"USD",
"original_total_price":229.99,
"items_subtotal_price":181.99,
"total_price":181.99,
"total_discount":18,
"total_weight":7,
"item_count":1,
"requires_shipping":true,
"cart_level_discount_applications":[
]
}
Scenario 2: The shopping cart code does not exist:
POST https://{handle}.myshopline.com/api/carts/ajax-cart/apply.js
status:404
{"message":"DISCOUNT_CODE_INVALID","description":"DISCOUNT_CODE_INVALID"}
Was this article helpful to you?
