patch
https://secure.fusebill.com/v1/DraftInvoices
A draft invoice that has not yet been posted and is in status “Ready” can have some modifications applied to it prior to being posted. This can be achieved by using the Patch Draft Invoice call to modify specific elements of the invoice. If an invoice line item has status pending, change the original subscription product or purchase instead.
Request Parameters
| Property | Type | Description | Required |
|---|---|---|---|
id | Integer | This is the Fusebill generated ID of the draft invoice you wish to modify. | Yes |
notes | String | Billing agents can write notes on draft invoices. Once posted the note is final. [Max Length: 500 characters] | Optional |
poNumber | String | The value in the PO Number field within the draft invoice. [Max Length: 255 characters] | Optional |
netTermsSet | Boolean | This primes Fusebill to change the invoice's net terms to something different than default. Pair this with netTerms to define which value to set. | Optional |
netTerms | Enum:{Net0, Net5, Net7, Net10, Net15, Net21, Net30, Net45, Net60, Net75, Net90, MFI1, DayOfMonth1, DayOfMonth2, DayOfMonth3, ... DayOfMonth29, DayOfMonth30, DayOfMonth31} | Set non-default net terms on the invoice. Requires netTermsSet to be true | Optional |
draftCharges | List of objects. Definition below | The set of draft charges belonging to the draft invoice you wish to modify or delete | Optional |
Draft Charges Object
| Property | Type | Description |
|---|---|---|
id | Integer | This is the Fusebill generated ID number of draft charge you wish to modify or delete. |
operation | Enum:{Update, Delete} | Indicates whether the draft charge is to be deleted or updated |
name | String | This is the name of the charge. [Max Length: 2000 characters] |
description | String | This is the description for the charge. [Max Length: 2000 characters] |
quantity | Decimal | This is the unit quantity of the charge |
unitPrice | Decimal | This is the price per unit |
rangeQuantity | Decimal | For non standard pricing, indicates the value used to calculate the price per unit. If the pricing model is Tiered, override the draftChargeTiers list instead |
proratedUnitPrice | Decimal | The price per unit of quantity if the charge is subject to proration. |
draftDiscounts | List of Objects. Defined below | The set of draft discounts for this draft charge you wish to insert, modify, or delete |
draftChargeTiers | List of Objects. Defined below | If the charge is based on a subscription product or purchase using the Tiered pricing model, then this list breaks down the draft charge into its tiers |
Draft Discount Object
| Property | Type | Description |
|---|---|---|
id | Integer | The Fusebill generated ID of the draft discount. Required for the update and delete operations |
configuredDiscountAmount | Decimal | The dollar amount or percentage configured for the discount, depending on discountType |
discountType | Enum: {Percentage, Amount, AmountPerUnit} | Indicates how configuredDiscountAmount is interpreted for calculating the discount |
description | String | The displayed description for the charge discount [Max Length: 2000 characters] |
operation | Enum: {insert, update, delete} | Indicates whether this is a new draft discount (insert), or if this is a modification/deletion of the draft discount with ID id |
Draft Charge Tier Object
| Property | Type | Description |
|---|---|---|
unitPrice | Decimal | The price per unit of quantity in this tier |
label | String | The label of this charge tier that will appear on the invoice. [Max Length: 100 characters] |
quantity | Decimal | How much of the charge's quantity is portioned to this tier. Note that if a patch is made such that the sum of draft charge tier quantities is no longer equal to the draft charge quantity, this has the effect of changing the draft charge quantity |
sortOrder | Integer | Indicates whether this update is to the draft charge tier in position 1 (top in the list), position 2 (second to the top in the list), etc |
Examples
curl -X PATCH "https://secure.fusebill.com/v1/DraftInvoices/" \
-H "Content-Type: application/json" \
-H "Authorization: Basic {APIKey}" \
-d "{id:{draftInvoiceId},notes:'I patched this note onto the draft invoice.'}"//Json Payload
string jsonData =
"{id:{draftInvoiceId},notes:'I patched this note onto the draft invoice.'}";
//Setup API key
string apiKey = "{APIKey}";
//Configure URI
WebRequest request = WebRequest.Create("HTTPS://secure.fusebill.com/v1/DraftInvoices/");
//Add Content type
request.ContentType = "application/json";
//Add Api key authorization
request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + apiKey);
//Set request method
request.Method = "PATCH";
//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 = {"id":{id},"notes":'I patched this note onto the draft invoice.'}
#Pass in your URI, Payload and Headers
r = requests.patch('https://secure.fusebill.com/v1/DraftInvoices', data=json.dumps(payload), headers=headers)
print(r.content){
"id": 123532,
"notes": "note value",
"poNumber": "PO 8000",
"draftCharges": [
{
"id": 132563645,
"operation": "update",
"description": "newDescription",
"name": "newName",
"quantity": 2
}
],
"netTermsSet": true,
"netTerms": "Net90"
}{
"id": 123532,
"notes": "note value",
"poNumber": "PO 8000",
"netTermsSet": true,
"netTerms": "Net90",
"draftCharges": [
{
"id": 132563645,
"operation": "update",
"name": "newName",
"description": "newDescription",
"quantity": 2,
"unitPrice": 40.5
},
{
"rangeQuantity": 4,
"operation": "update",
"id": 132563646
},
{
"proratedUntPrice": 3.5,
"operation": "update",
"id": 132563647
},
{
"id": 132563648,
"operation": "update",
"draftDiscounts": [
{
"configuredDiscountAmount": 3,
"discountType": "Amount",
"description": "$3 off",
"operation": "insert"
},
{
"id": 34324,
"configuredDiscountAmount": 3,
"discountType": "Amount",
"description": "$3 off",
"operation": "update"
}
],
"draftChargeTiers": [
{
"unitPrice": 3.99,
"label": "0 to 4",
"quantity": 4,
"sortOrder": 1
},
{
"unitPrice": 2.99,
"label": "4 up",
"quantity": 4,
"sortOrder": 2
}
]
}
]
}Response
{
"billingPeriodId":182592,
"effectiveTimestamp":"2017-02-11T05:00:00",
"status":"Projected",
"poNumber":null,
"draftCharges":[
{
"transactionId":0,
"chargeTypeId":null,
"transactionType":"Charge",
"quantity":1.0,
"unitPrice":15.99,
"amount":15.99,
"taxableAmount":15.99,
"subscriptionPeriodId":0,
"draftInvoiceId":0,
"name":"Monthly Charge",
"description":null,
"effectiveTimestamp":"2017-02-11T05:00:00",
"proratedUnitPrice":null,
"startServiceDate":"2017-02-11T05:00:00",
"endServiceDate":"2017-03-11T05:00:00",
"rangeQuantity":null,
"draftDiscount":null,
"draftDiscounts":[
],
"status":"Projected",
"productItems":null,
"canProrateCharge":false,
"postable":true,
"id":1008956,
"uri":null
}
],
"subtotal":15.9900,
"totalDiscount":0.0,
"total":15.9900,
"taxes":[
],
"paymentSchedules":[
],
"customer":{
"reference":"1337",
"companyName":"Stolen Bikes",
"fullName":"Mr John Doe",
"contactName":"Mr John Doe",
"primaryPhone":"613-555-5555",
"primaryEmail":"[email protected]",
"billingAddress":null,
"shippingAddress":null,
"invoicePreference":{
"signature":"<p><strong>Kennedy Consulting</strong> \r</p>\n<p>, \r</p>\n<p><em>Kennedy Consulting | | [][1]</em></p>\n<p>[1]: </p>\n",
"standingPoNumber":null,
"invoiceNotes":null
}
},
"notes":null,
"shippingInstructions":null,
"customerReferenceValue":"1337",
"terms":"Net5",
"id":169033,
"uri":"https://secure.fusebill.com/v1/DraftInvoices/169033"
}{
"ErrorId": 0,
"HttpStatusCode": 400,
"Errors": [
{
"Key": "Api Error",
"Value": "Charges cannot be edited when the draft invoice is in status Pending"
}
]
}