post https://secure.fusebill.com/v1/Purchases/BulkCreate
This function is used to create a set of Purchases for a Customer. By default, the Purchases will be added in Draft status and must be finalized before it charges against the Customer account. Optionally, you can set these purchases to auto-finalize and purchase immediately.
Note, the Purchases key/value is a nested list which allows you to post any number of purchases as its own list.
Request Parameters
Property | Type | Description | Required |
---|---|---|---|
customerId | Integer | This is the ID of the Customer making the purchases | Yes |
autoPurchase | Boolean | This flag determines if the system should enter the Purchases as Draft Purchases or if the system should auto finalize the Purchases and charge for them immediately. If set to True, Fusebill will auto finalize the Purchases. If set to False, the Purchases will be added to the Customer in Draft mode. | Optional |
purchases | List of Objects. Defined below | This is a list of Purchases which the Customer is attempting to make. | Yes |
invoiceCollectOptions | Object. Defined below | This can be used to provide special invoice collection instructions for the invoice which may be generated if autoPurchase is true | Optional |
Purchase fields
Property | Type | Description | Required |
---|---|---|---|
productId | Integer | The Fusebill generated ID of the purchasable product | Yes |
name | String | The name of the purchase. [Max Length: 2000] | Yes |
description | String | The description of the purchase. [Max Length: 2000] | Optional |
quantity | Decimal | The quantity being purchased. Used by the pricing model and price ranges to calculate the overall price. If the purchase is using tracked quantities, leave this null | Optional. Default is zero. |
targetOrderQuantity | Decimal | The number of tracked items which must be on this purchase in order to be considered fulfilled. If this is not met, the purchase cannot be finalized. Cannot be used for purchases which are not tracking items. | Optional |
overridePriceRanges | List of Objects. Defined below | The price ranges used to determine the amount to charge. For the standard pricing model, this is a single range from 0 to infinity with a single price. This is an override just for this purchase. | Optional |
pricingModelType | Enum: {Tiered, Volume, Standard, Stairstep} | Can be used to override the pricing model being used just for this purchase. | Optional |
customFields | List of Objects. Defined below | Custom fields can be added to the purchase. Custom Fields are key-value pairs | Optional |
discounts | List of Objects. Defined below | Ad hoc discounts can be provided without the need of coupon codes. | Optional |
productItems | List of Objects. Defined below | If the product has tracked quantities enabled, then this is the list of tracked items for this purchase | Optional |
couponCodes | List of Strings | Each string is a coupon code instructing Fusebill which coupon should be applied to the purchase | Optional |
earningSettings | Object. Defined below | Controls how this purchase earns. Defaults to the catalog options | Optional |
netsuiteLocationId | String | The location of this purchase in NetSuite. [Max Length: 100 characters] | Optional |
Override Price Ranges Fields
Property | Type | Description |
---|---|---|
min | Decimal | The lower bound of the range |
max | Decimal | The upper bound of the range. Null is interpreted as infinity |
amount | Decimal | The price for this range |
Custom Field Object
Property | Type | Description |
---|---|---|
key | string | This is the unique key of the Custom Field |
value | string | This is the value you wish to update the custom field to. This will always be the string version of the value. If you wish to pass a number, for example, pass it as "123". Likewise, a DateTime would be passed as "2014-06-26T04:00:00". We will use the known data type of the custom field to properly convert the String to a Number, DateTime, etc. [Max Length: 1000 characters] |
Discounts Fields
Property | Type | Description |
---|---|---|
discountType | Enum: {Percentage, Amount, AmountPerUnit} | Indicates how amount is interpreted for calculating the discount |
amount | Decimal | The dollar amount or percentage, depending on discountType |
Product Items Fields
Property | Type | Description |
---|---|---|
reference | String | The unique reference for this tracked item [Max Length: 255 characters] |
name | String | The name of this tracked item [Max Length: 100 characters] |
description | String | The description for this tracked item [Max Length: 255 characters] |
Invoice collection options
Property | Type | Description |
---|---|---|
paymentMethod | Enum: {UseDefaultPaymentMethod, UseExistingPaymentMethod, UseExistingPaymentMethodAndMakeDefault, UseProvidedPaymentMethodOnce, UseProvidedPaymentMethodAndMakeDefault, UseProvidedPaymentMethodAndSave, CreateAndApplyCredit} | Controls which payment method to use |
paymentMethodId | Integer | The Fusebill generated ID of the payment method. Provide this only if paymentMethod is "UseExistingPaymentMethod" or "UseExistingPaymentMethodAndMakeDefaul" |
useAnyAvailableFundsFirst | Boolean | Controls whether available funds on the customer entity should be used first. |
creditCard | Object | See credit card creation parameters as outlined in Create Credit Card Payment Method |
achCard | Object | See ACH card creation parameters as outlined in Create ACH Payment Method |
rollbackOnFailedPayment | Boolean | If payment fails, Fusebill can undo the purchase completion and prevent the invoice from posting. |
Earning Settings Object
Property | Type | Description |
---|---|---|
earningInterval | Enum: {Monthly, Yearly} | Indicates whether the custom earning period (if a custom earning period is being used) is measured in years or months |
earningNumberOfIntervals | Integer | The number of earningInterval s that constitute the period this purchase earns over |
earningTimingInterval | Enum:{Daily, Monthly, Yearly, Interval, DoesNotEarn, EarnImmediately} | Indicates how to divide the custom period if a custom period is being used, indicates the purchase does not earn, or indicates that the purchase earns immediately |
earningTimingType | Enum:{StartOfInterval, EndOfInterval, DoesNotEarn} | Indicates where in the interval the earning occurs, if custom earning periods are being used |
Examples
curl -X POST "https://secure.fusebill.com/v1/Purchases/BulkCreate" \
-H "Content-Type: application/json" \
-H "Authorization: Basic {APIKey}" \
-d "{customerId:{CustomerId},autoPurchase:false,purchases:[{productId:{ProductId},name:'purchase1'},{productId:{ProductId},name:'purchase2'}]}"
//Json Payload
string jsonData = "{customerId:{CustomerId},autoPurchase:false,purchases:[{productId:{ProductId},name:'purchase1'},{productId:{ProductId},name:'purchase2'}]}";
//Setup API key
string apiKey = "{APIKey}";
//Configure URI
WebRequest request = WebRequest.Create("HTTPS://secure.fusebill.com/v1/Purchases/BulkCreate");
//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 = {"customerId":{id},"autoPurchase": "false", "purchases":[{"productId":{id},"name": "product-3"}]}
#Pass in your URI, Payload and Headers
r = requests.post('https://secure.fusebill.com/v1/purchases/bulkCreate', data=json.dumps(payload), headers=headers)
print(r.content)
{
"customerId": 655642,
"autoPurchase": true,
"purchases": [
{
"name": "purchase1",
"quantity": 1,
"productId": 46772
},
{
"name": "purchase2",
"quantity": 3,
"productId": 46775
},
{
"name": "purchase3",
"quantity": 4,
"productId": 46773
},
{
"name": "purchase4",
"quantity": 2,
"productId": 46771
}
]
}
{
"customerId": 655642,
"autoPurchase": true,
"purchases": [
{
"name": "T-Shirt",
"description": "Yellow",
"quantity": 4,
"overridePriceRanges": [
{
"min": 0,
"max": 2,
"amount": 50
},
{
"min": 2,
"max": null,
"amount": 150
}
],
"pricingModeltype": "Volume",
"customFields": [
{
"key": "Sales Rep",
"value": 1234
}
],
"discounts": [
{
"discountType": "Percentage",
"amount": 50
}
],
"productItems": null,
"couponCodes": [
"code1"
],
"earningSettings": {
"earningInterval": "Monthly",
"earningNumberOfIntervals": 1,
"earningTimingInterval": "Daily",
"earningTimingType": "StartOfInterval"
},
"productId": 46777
},
{
"name": "T-Shirt",
"description": "Green",
"quantity": 2,
"overridePriceRanges": [
{
"min": 0,
"max": 2,
"amount": 50
},
{
"min": 2,
"max": null,
"amount": 150
}
],
"pricingModeltype": "Volume",
"customFields": [
{
"key": "Sales Rep",
"value": 1235
}
],
"discounts": [
{
"discountType": "Percentage",
"amount": 50
}
],
"productItems": null,
"couponCodes": [
"code1"
],
"earningSettings": {
"earningInterval": "Monthly",
"earningNumberOfIntervals": 1,
"earningTimingInterval": "Daily",
"earningTimingType": "StartOfInterval"
},
"productId": 46777
}
],
"invoiceCollectOptions": {
"paymentMethod": "useDefaultPaymentMethod",
"paymentMethodId": null,
"useAnyAvailableFundsFirst": true,
"creditCard": null,
"achCard": null,
"rollbackOnFailedPayment": true
}
}
{
"customerId": 655642,
"autoPurchase": true,
"purchases": [
{
"name": "Thermostats",
"description": "Smart Home Catalog",
"quantity": null,
"overridePriceRanges": [
{
"min": 0,
"max": 2,
"amount": 50
},
{
"min": 2,
"max": null,
"amount": 150
}
],
"pricingModeltype": "Volume",
"customFields": [
{
"key": "Sales Rep",
"value": 1234
}
],
"discounts": [
{
"discountType": "Percentage",
"amount": 50
}
],
"productItems": [
{
"reference": 1234156785243216,
"name": "Thermostat",
"description": "MODEL MC1-0092"
}
],
"couponCodes": [
"code1"
],
"productId": 46777
}
],
"invoiceCollectOptions": {
"paymentMethod": "useDefaultPaymentMethod",
"paymentMethodId": null,
"useAnyAvailableFundsFirst": true,
"creditCard": null,
"achCard": null,
"rollbackOnFailedPayment": true
}
}
Response
{
"customerId":172677,
"purchases":[
{
"productId":17501,
"name":"purchase1",
"description":"One off charges",
"status":"Draft",
"quantity":0.0,
"targetOrderQuantity": null,
"isTrackingItems":false,
"pricingModelType":"Standard",
"customFields":[],
"discounts":[],
"priceRanges":[
{
"min":0.000000,
"max":null,
"amount":1.000000
}
],
"productItems":[],
"couponCodes":[],
"earningSettings":null,
"id":43942,
"uri":"https://secure.fusebill.com/v1/Purchases/43942"
},
{
"productId":17501,
"name":"purchase2",
"description":"One off charges",
"status":"Draft",
"quantity":0.0,
"isTrackingItems":false,
"pricingModelType":"Standard",
"customFields":[],
"discounts":[],
"priceRanges":[
{
"min":0.000000,
"max":null,
"amount":1.000000
}
],
"productItems":[],
"couponCodes":[],
"earningSettings":null,
"id":43941,
"uri":"https://secure.fusebill.com/v1/Purchases/43941"
}
]
}
{
"ErrorId": 0,
"HttpStatusCode": 400,
"Errors": [
{
"Key": "bulkPurchase.Purchases[0]",
"Value": "Quantity is not valid when tracking items."
}
]
}