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 nameParameter typeRequiredArray or notDefault valuedescribe
Content-TypeStringYNapplication/json
cookieStringYNSHOPLINE cookie

request body:

Parameter nameParameter nameParameter typeRequiredArray or notExampledescribe
codeObjectYNShopping cart code

Response information

Response body:

Parameter nameParameter nameParameter nameParameter nameParameter typeArray or notExampledescribe
itemsObjectYShopping cart item list
idStringN36110175633573The unique identification of the product is SKU_ id
group_idStringN0Item group ID
quantityIntegerN2Quantity of goods
propertiesLongNimage.png
  • Name: User-defined attribute name
  • Value: custom attribute value
  • Type: type, attribute enumeration has three types: text, picture and link, text: character, display type is name: value; Picture: picture, display type is name: get and render thumbnail through urls, click the pop-up to display the thumbnail, and support download; Link: hyperlink, display type is name: value, support clicking to jump to the first url
  • Show: Whether to display at the front desk
  • ExtInfo: extended field
  • variant_idStringN36110175633573Item SKU_ id
    titleStringNtest1Product title + SKU title name + specification
    priceDoubleN200Commodity price
    original_priceDoubleN200Original price of goods (may be 0)
    discounted_priceDoubleN200Price after discount
    line_priceDoubleN200Commodity line selling price
    original_line_priceDoubleN200Original price of commodity line (may be 0)
    total_discountDoubleN200Total discount amount of a single item
    discountsObjectYDiscount of commodity bank
    amountDoubleN200Preferential amount
    titleStringN50 minus 100Preferential name
    skuStringNRed XLItem SKU_ id
    gramsStringN100Commodity weight unit: G
    taxableBooleanNtrueWhether to collect tax
    product_idStringN36110175633573Commodity SPU_ id
    gift_cardBooleanNtrueIs it a gift card product
    final_priceDoubleN500Amount of goods involved in pricing
    final_line_priceDoubleN500Amount of commodity line participating in pricing
    urlStringNhttps://ddfasdfasdfCommodity master link
    featured_imageStringN
    aspectRatioDoubleNAspect ratio
    altStringNMouse over prompt
    heightIntegerNDisplay height
    urlStringNpicture
    widthIntegerNDisplay width
    imageStringNProduct image
    handleStringNProduct handle
    requires_shippingStringNWhether shipment is required
    product_titleStringNProduct title
    variant_titleStringNSplicing of all specifications
    variant_optionsStringNEnumeration of all specifications
    options_with_valuesStringNSpecifications
    nameStringNSpecifications name
    valueStringNSpecifications value
    line_level_discount_allocationsStringNDiscount of commodity bank information
    amountDoubleNPreferential amount
    discountApplicationStringN
    typeIntegerN
  • 1: Price concessions
  • 2: discount
  • 3: freight free
  • 7: gifts
  • 8: fixed price discount
  • 9: free minimum goods
  • 11: m-PIECE discount
  • 12: buy x get y free
  • 101: table deduction amount
  • 102: table deduction percentage
  • 103: member discount
  • 104: discount code
  • 105: designated shopping money
  • 106: points
  • titleStringNPreferential name
    descriptionStringNOffer describe
    valueDoubleNPreferential amount
    created_atStringNActivity creation time
    value_typeStringNDiscount activity type:
  • Percentage discount
  • fix_ Amount fixed amount
  • target_typeStringN
  • Preferential target
  • line_ Item item
  • shipping_ Line freight
  • codeStringNcode
    statusStringNstatus enable unable
    line_level_total_discountDoubleNTotal 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?