Create Bulk Purchase

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

PropertyTypeDescriptionRequired
customerIdIntegerThis is the ID of the Customer making the purchasesYes
autoPurchaseBooleanThis 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
purchasesList of Objects. Defined belowThis is a list of Purchases which the Customer is attempting to make.Yes
invoiceCollectOptionsObject. Defined belowThis can be used to provide special invoice collection instructions for the invoice which may be generated if autoPurchase is trueOptional

Purchase fields

PropertyTypeDescriptionRequired
productIdIntegerThe Fusebill generated ID of the purchasable productYes
nameStringThe name of the purchase. [Max Length: 2000]Yes
descriptionStringThe description of the purchase. [Max Length: 2000]Optional
quantityDecimalThe 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 nullOptional. Default is zero.
targetOrderQuantityDecimalThe 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
overridePriceRangesList of Objects. Defined belowThe 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
pricingModelTypeEnum: {Tiered, Volume, Standard, Stairstep}Can be used to override the pricing model being used just for this purchase.Optional
customFieldsList of Objects. Defined belowCustom fields can be added to the purchase. Custom Fields are key-value pairsOptional
discountsList of Objects. Defined belowAd hoc discounts can be provided without the need of coupon codes.Optional
productItemsList of Objects. Defined belowIf the product has tracked quantities enabled, then this is the list of tracked items for this purchaseOptional
couponCodesList of StringsEach string is a coupon code instructing Fusebill which coupon should be applied to the purchaseOptional
earningSettingsObject. Defined belowControls how this purchase earns. Defaults to the catalog optionsOptional
netsuiteLocationIdStringThe location of this purchase in NetSuite. [Max Length: 100 characters]Optional

Override Price Ranges Fields

PropertyTypeDescription
minDecimalThe lower bound of the range
maxDecimalThe upper bound of the range. Null is interpreted as infinity
amountDecimalThe price for this range

Custom Field Object

PropertyTypeDescription
keystringThis is the unique key of the Custom Field
valuestringThis 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

PropertyTypeDescription
discountTypeEnum: {Percentage, Amount, AmountPerUnit}Indicates how amount is interpreted for calculating the discount
amountDecimalThe dollar amount or percentage, depending on discountType

Product Items Fields

PropertyTypeDescription
referenceStringThe unique reference for this tracked item [Max Length: 255 characters]
nameStringThe name of this tracked item [Max Length: 100 characters]
descriptionStringThe description for this tracked item [Max Length: 255 characters]

Invoice collection options

PropertyTypeDescription
paymentMethodEnum: {UseDefaultPaymentMethod, UseExistingPaymentMethod, UseExistingPaymentMethodAndMakeDefault, UseProvidedPaymentMethodOnce, UseProvidedPaymentMethodAndMakeDefault, UseProvidedPaymentMethodAndSave, CreateAndApplyCredit}Controls which payment method to use
paymentMethodIdIntegerThe Fusebill generated ID of the payment method. Provide this only if paymentMethod is "UseExistingPaymentMethod" or "UseExistingPaymentMethodAndMakeDefaul"
useAnyAvailableFundsFirstBooleanControls whether available funds on the customer entity should be used first.
creditCardObjectSee credit card creation parameters as outlined in Create Credit Card Payment Method
achCardObjectSee ACH card creation parameters as outlined in Create ACH Payment Method
rollbackOnFailedPaymentBooleanIf payment fails, Fusebill can undo the purchase completion and prevent the invoice from posting.

Earning Settings Object

PropertyTypeDescription
earningIntervalEnum: {Monthly, Yearly}Indicates whether the custom earning period (if a custom earning period is being used) is measured in years or months
earningNumberOfIntervalsIntegerThe number of earningIntervals that constitute the period this purchase earns over
earningTimingIntervalEnum:{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
earningTimingTypeEnum:{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."
        }
    ]
}
Language
Authorization