Patch Subscription Product Items

The PATCH Subscription Product Items endpoint can include multiple collections of tracked item fields so that multiple updates, inserts, and/or deletes can be completed at one time, and in one single API request.

Remember, the reference for each individual tracked item must still be unique. For the best performance, we recommend that no more than 100 tracked items be created in a single call.

Some general notes on using the PATCH Subscription Product Items endpoint:

  • To complete the PATCH request, you will need the "Subscription ID" and the "Subscription Product ID". In addition, for the Update and Delete operations you will also need the “Subscription Product Item ID”.
  • The Operation key-value pair within each subscriptionProductItems collection will define the action on the given subscription product item. The available values for this key are "Insert", "Delete", and "Update".
  • When using the Delete operation, the status of the tracked item will change from “Active” to “Deleted”. You can re-use the unique reference that exists on Deleted tracked items.

URL Parameters

PropertyTypeDescription
previewBooleanIf true, results in no system change. Instead, a preview of the item and the resulting invoice and charges are returned as a response. False by default
temporarilyDisableAutoPostBooleanIf true, then the invoice that might otherwise automatically be posted as a result of this PATCH will instead be created in 'draft' form. False by default
showZeroDollarChargesBooleanIf true, then the invoice that might be generated by this request will show zero dollar charges as line items. False by default.

Request Parameters

PropertyTypeDescriptionRequired
subscriptionIdIntegerThe Fusebill generated ID that uniquely identifies the subscriptionYes
invoiceCollectOptionsObject. Defined belowThis can be used to provide special invoice collection instructions for the invoice which may be generated by this API call. An invoice may be generated if an additional (priced) tracked quantity is inserted into a subscription productOptional
subscriptionProductsList of objects. Defined belowThe list of subscription products whose tracked items are being modifiedYes

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 roll back the transaction and prevent the invoice from posting.

Subscription Products List Fields

PropertyTypeDescription
subscriptionProductIdIntegerThe Fusebill generated ID that uniquely identifies the subscription product
subscriptionProductItemsList of objects. Defined belowThe individual tracked items being modified on this subscription product, added to this subscription product, or removed from this subscription product

Subscription Product Items List Fields

PropertyTypeDescription
SubscriptionProductItemsIdIntegerThis is the unique ID of the subscription product item. If this is a new subscription product item (i.e Operation is "Insert") then this is not needed
NameStringAn optional field for storing custom data, intended to be the name of the item
[Max Length: 100 characters]
DescriptionStringAn optional field for storing custom data, intended to be a description of the item.
[Max Length: 255 characters]
ReferenceStringThe unique identifier for this tracked item. See above for uniqueness constraint
[Max Length: 255 characters]
OperationEnum:{Insert, Delete, Update}This is the operation being done. If the operation is 'Update' then any provided name, description, or reference will be used to override the existing value.
Examples
#Import library JSON
import json
#Import library Requests
import requests
#Pass in a dictionary to the Headers parameter
headers = {'Authorization' : 'Basic {API Key}', 'Content-Type' : 'application/json'}
#Define Payload parameter
payload = { "subscriptionId":{id}, "subscriptionProducts":[ { "subscriptionProductId":{id}, "subscriptionProductItems":[ { "reference":"0000096", "name":"item name", "description":"optional description", "operation":"insert" }, { "subscriptionProductItemsId":{id}, "name":"new name", "operation":"update" }, { "subscriptionProductItemsId":{id}, "reference":"0000094", "name":"test sub item", "description":"description", "operation":"delete" } ] } ] } 
#Pass URI, Payload and Headers into the Requests method
r = requests.patch('https://secure.fusebill.com/v1/subscriptionproductitems/', data=json.dumps(payload), headers=headers)
print(r.content)
//Json Payload
string jsonData = "{subscriptionId: 1, subscriptionProducts: [{subscriptionProductId: 1, subscriptionProductItems: [{         subscriptionProductItemId: 1, reference: "sample string 2", name: "sample string 4", description: "sample string 6", operation: "sample string 8"},]}";
//Setup API key
string apiKey = "{APIKey}";
//Configure URI
WebRequest request = WebRequest.Create("HTTPS://secure.fusebill.com/v1/SubscriptionProductItems?preview={preview}&showZeroDollarCharges={showZeroDollarCharges}&temporarilyDisableAutoPost={temporarilyDisableAutoPost}");
//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();
}
curl -X PATCH  "SubscriptionProductItems?preview={preview}&showZeroDollarCharges={showZeroDollarCharges}&temporarilyDisableAutoPost={temporarilyDisableAutoPost}" \
    -H "Content-Type: application/json" \
    -H "Authorization: Basic {APIKey}" \
    -d "{subscriptionId: 1, subscriptionProducts: [{subscriptionProductId: 1, subscriptionProductItems: [{         subscriptionProductItemId: 1, reference: "sample string 2", name: "sample string 4", description: "sample string 6", operation: "sample string 8"},]}";
{
  "subscriptionId": 305425,
  "subscriptionProducts": [
    {
      "subscriptionProductId": 2334138,
      "subscriptionProductItems": [
        {
          "name": "newName",
          "reference": "newReference",
          "operation": "Update",
          "description": "newDescription",
          "subscriptionProductItemId": 242751
        },
        {
          "operation": "Delete",
          "subscriptionProductItemId": 242742
        },
        {
          "name": "NameOfTheNewItem",
          "reference": "RefOfTheNewItem",
          "operation": "Insert",
          "description": "DescOfTheNewItem"
        }
      ]
    }
  ]
}
Response
{
    "subscriptionId": 305425,
    "invoicePreview": null,
    "additionalInvoicesForPreview": null,
    "subscriptionProducts": [
        {
            "subscriptionProductId": 2334140,
            "subscriptionProductItems": []
        },
        {
            "subscriptionProductId": 2334139,
            "subscriptionProductItems": []
        },
        {
            "subscriptionProductId": 2334138,
            "subscriptionProductItems": [
                {
                    "reference": "123459651622156",
                    "name": "Thermostat",
                    "description": "MODEL MC1-0092",
                    "subscriptionProductId": 2334138,
                    "subscriptionId": 305425,
                    "customerId": 643539,
                    "productId": 46818,
                    "status": "Deleted",
                    "createdDate": "2019-11-01T11:51:26",
                    "modifiedDate": "2019-11-12T15:34:57.3323291Z",
                    "id": 242386,
                    "uri": "https://secure.fusebill.com/v1/subscriptionproductitems/242386"
                }
            ]
        }
    ]
}
{
    "ErrorId": 0,
    "HttpStatusCode": 400,
    "Errors": [
        {
            "Key": "Api Error",
            "Value": "Unable to create tracked items, subscription product 2334140 is not tracking unique quantities."
        }
    ]
}
Language
Authorization