post https://secure.fusebill.com/v1/PurchaseCoupons
This function is used to apply a coupon to a purchase before it has been finalized.
Request Parameters
Property | Type | Description |
---|---|---|
PurchaseId | Integer | This is the ID value of the Purchase you want to apply the coupon against. |
couponCode | String | This is the coupon code which identifies the Coupon you want to apply to the specified Purchase. |
Examples
curl -X POST "https://secure.fusebill.com/v1/PurchaseCoupons" \
-H "Content-Type: application/json" \
-H "Authorization: Basic {APIKey}" \
-d "{PurchaseId:{PurchaseId},couponCode:'{CouponCode}'}"
//Json Payload
string jsonData = "{PurchaseId:{PurchaseId}, couponCode:'{CouponCode}'}";
//Setup API key
string apiKey = "{APIKey}";
//Configure URI
WebRequest request = WebRequest.Create("HTTPS://secure.fusebill.com/v1/PurchaseCoupons");
//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 = {"purchaseId": {id},"couponCode":"fixed10"}
#Pass in your URI, Payload and Headers
r = requests.post('https://secure.fusebill.com/v1/PurchaseCoupons', data=json.dumps(payload), headers=headers)
print(r.content)
{
"purchaseId": 123459,
"couponCode": "seniorDiscount"
}
Response
{
"purchaseId":43942,
"couponCode":"newbie6mnth",
"id":0,
"uri":"https://secure.fusebill.com/v1/PurchaseCoupons/0"
}
{
"ErrorId": 0,
"HttpStatusCode": 400,
"Errors": [
{
"Key": "Api Error",
"Value": "Only purchases in draft can have coupons changed"
}
]
}