Apply Coupon to Subscription

This function is used to apply a coupon to a customer's subscription. It is recommended you call the validate coupon call first to ensure this coupon can be applied to the subscription.

📘

Discounts from coupons will not apply to unincluded products.

When adding a coupon to a subscription, the discounts will only be applied if the products have already been included. If an invoice is already in the Draft - Ready or Posted state, it is too late for a discount from a coupon to be applied.

Request Parameters

PropertyTypeDescriptionRequired
subscriptionIdIntegerThis is the ID value which uniquely identifies the Subscription record in the Fusebill system.Yes
couponCodeStringThis is the coupon code which uniquely identifies the coupon you want to apply to the subscription.Conditional. Required if couponCodes is not provided.
couponCodesList of StringsTo apply more than one code, use this to list several coupon codes.Conditional. Required if couponCode is not provided.
Examples
curl -X POST "https://secure.fusebill.com/v1/SubscriptionCoupons" \
	-H "Content-Type: application/json" \
	-H "Authorization: Basic {APIKey}" \
	-d "{subscriptionId:{subscriptionId},couponCode:'{couponCode}'}"
//Json Payload
string jsonData = "{subscriptionId:{subscriptionId},couponCode:'{couponCode}'}";
//Setup API key
string apiKey = "{APIKey}";
//Configure URI
WebRequest request = WebRequest.Create("HTTPS://secure.fusebill.com/v1/SubscriptionCoupons/");
//Add Content type
request.ContentType = "application/json";
//Add Api key authorization
request.Headers.Add(HttpRequestHeader.Authorization, "Basic "+apiKey);
//Set request method
request.Method = "POST";
//Add the json data to request
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
  streamWriter.Write(jsonData);
  streamWriter.Flush();
  streamWriter.Close();
}
//Perform the request
var httpResponse = (HttpWebResponse)request.GetResponse();
//Record the response from our request
var result = "";
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
  result = streamReader.ReadToEnd();
}
#Import library JSON
import json
#Import library Requests
import requests
#Pass in a dictionary to the Headers parameter
headers = {'Authorization' : 'Basic {APIKey}', 'Content-Type' : 'application/json'}
#Pass in a dictionary to the Payload parameter
payload = {"subscriptionId":{id},"couponCode":'ApplyThis'}
#Pass in your URI, Payload and Headers
r = requests.post('https://secure.fusebill.com/v1/SubscriptionCoupons', data=json.dumps(payload), headers=headers)
print(r.content)
{
  "subscriptionId": 51234,
  "couponCode": "SD12"
}
{
  "subscriptionId": 51234,
  "couponCodes": [
    "SD12",
    "SD14"
    ]
}
Response
{ 
   "subscriptionId":123061,
   "couponCode":"new6mnth",
   "id":14712,
   "uri":"https://secure.fusebill.com/v1/SubscriptionCoupons/14712"
}
{
    "ErrorId": 0,
    "HttpStatusCode": 400,
    "Errors": [
        {
            "Key": "Api Error",
            "Value": "Coupon not found"
        }
    ]
}
Language
Authorization