Marketing API
Discounts
Create Product Discount
this api endpoint (post) (post) creates a discount for one or multiple products if the request succeeds, it returns a discount object docid\ y 9znrh28cmsoyhovk7fm permissions discounts create webhook event discount events docid\ amoqkwqv4lrhgmpdygehw body parameters label string the label of the discount currency string appendix docid\ kfbmx4q3dxjtduqf75yx1 the currency of the discount percent off decimal the percentage discount applied to the order and/or product subtotal amount off integer the fixed discount amount applied to the order and/or product subtotal shipping amount off integer the fixed discount amount applied to the shipping subtotal shipping percent off decimal the percentage discount applied to the shipping subtotal condition string the possible values are coupon , vouchers , all orders , item subtotal and item quantity applies to string the possible values are all products , selected products and selected categories active boolean determines whether the discount is currently active the default value is false payments array of strings appendix docid\ kfbmx4q3dxjtduqf75yx1 the payment whitelist for the discount when set, the discount will apply if the customer selects any of the whitelisted payments to complete a purchase destinations array of strings ( appendix docid\ kfbmx4q3dxjtduqf75yx1 ) the country whitelist of the discount when set, the discount will apply if the customer's billing country matches any of the whitelisted destinations rule amount integer the amount that has to be met for the discount to activate for example, 100 items in an order or a $100 order value required if the condition is set to item subtotal or item quantity subscription discount duration string shows how the discount will be applied for subscription products the possible values are forever , once and repeating the default value is once number of months integer the total number of months the discount will be applied for recurring subscriptions required if subscription discount duration is set to repeating domain string the id of the domain that this discount is valid for coupon string the coupon code, for example, blackfriday required if condition is set to coupon coupon max redemptions integer the number of times the coupon can be redeemed available if condition is set to coupon if not provided, then the coupon can be redeemed unlimited times products array of strings the product object docid 4hx r lwtyahq1 pey1da ids associated with the discount required if applies to is set to selected products categories object an object containing the categories configuration of the discount required if applies to is set to selected categories for the category values see products docid\ gaxf8cqa3te sjlpubl7a { "physical" \['general'], "digital" \['ebooks'], "services" \[], "billing plans" \[] } voucher method string the possible values are autogenerated and list required if condition is set to vouchers voucher prefix string a custom prefix to use when generating the vouchers number of vouchers integer the total number of vouchers to generate the maximum is 1000 required if voucher method is set to autogenerated vouchers array of strings the voucher codes required if voucher method is set to list expiry date appendix docid\ kfbmx4q3dxjtduqf75yx1 the expiration date of the discount require "uri" require "json" require "net/http" url = uri("https //api tamio com/v2/discounts/product discount/create") https = net http new(url host, url port) https use ssl = true request = net http post new(url) request\["accept"] = "application/json" request\["authorization"] = "bearer your token here" data = { label "black friday shipping discount", active true, applies to "all products", currency "eur", percent off 0, amount off 0, shipping amount off 10, shipping percent off 0, condition "coupon", coupon "blackfriday", coupon max redemptions 100, block affiliates true } request body = data to json response = https request(request) puts response read body "categories" { "type" \["object", null], "additionalproperties" false, "properties" { "physical" { "type" "array", "maxitems" 20, "items" { "type" "string", "format" "physical categories" } }, "digital" { "type" "array", "maxitems" 20, "items" { "type" "string", "format" "digital categories" } }, "services" { "type" "array", "maxitems" 20, "items" { "type" "string", "format" "services subscription categories" } }, "billing plans" { "type" "array", "maxitems" 10, "uniqueitems" true, "items" { "type" "string", "format" "billing plan categories" } } } }, "destinations" { "type" "array", "minitems" 1, "maxitems" 120, "items" { "type" "string", "format" "all supported destinations" }, "default" \[ "worldwide" ] } },curl location request post 'https //api tamio com/v2/discounts/product discount/create' \\ \ header 'accept application/json' \\ \ header 'authorization bearer your token here' \\ \ data raw '{ "label" "black friday shipping discount", "active" true, "applies to" "all products", "currency" "eur", "percent off" 0, "amount off" 0, "shipping amount off" 10, "shipping percent off" 0, "condition" "coupon", "coupon" "blackfriday", "coupon max redemptions" 100, "block affiliates" true }'var myheaders = new headers(); myheaders append("accept", "application/json"); myheaders append("authorization", "bearer your token here"); var data = { label "black friday shipping discount", active true, applies to "all products", currency "eur", percent off 0, amount off 0, shipping amount off 10, shipping percent off 0, condition "coupon", coupon "blackfriday", coupon max redemptions 100, block affiliates true }; var body = json stringify(data); var requestoptions = { method 'post', headers myheaders, body body }; fetch("https //api tamio com/v2/discounts/product discount/create", requestoptions) then(response => response text()) then(result => console log(result)) catch(error => console log('error', error));{ "status" 200, "discount" { "id" "f23b029d 58dd 4bab 8cf1 a89d3ebb8f6d", "label" "black friday shipping discount", "currency" "eur", "percent off" 0, "amount off" 0, "shipping percent off" 0, "shipping amount off" 10, "active" false, "type" "product discount", "object" "discount", "payments" \[ "all" ], "created at" "2022 11 22 20 30 55 +0000", "expiry date" null, "block affiliates" true, "destinations" \[ "worldwide" ], "condition" "coupon", "applies to" "all products", "rule amount" null, "subscription discount duration" "once", "number of months" null, "domain" null, "coupon" "blackfriday", "coupon max redemptions" 100, "coupon times redeemed" 0 } }