Invoice Item

An invoice contains a list of InvoiceItems. An invoice item a single item charged on an invoice. Given an active subscription, one could see multiple items for that subscription on a single invoice, including recurring items, usage items, fixed price items, etc. There can also be items for different subscriptions on the same invoice, as well as items that are unrelated to subscriptions, such as adjustments and taxes.

InvoiceItem Resource

An InvoiceItem resource represents a single item charged on an invoice. The attributes contained in this resource are the following:

Name Type Generated by Description
invoiceItemId string system UUID for the invoice item
invoiceId string system UUID for the invoice
linkedInvoiceItemId string system UUID for the linked item, if any (see below)
accountId string system UUID for the account
childAccountId string system In the hierarchical model, the UUID of the child account
bundleId string system UUID for the bundle
subscriptionId string system UUID for the subscription (present only if invoice item corresponds to a subscription)
productName string system Name of the Product for this subscription if any
planName string system Name of the Plan for this subscription if any
phaseName string system Name of the PlanPhase for this subscription if any
usageName string system Name of the Usage section for this subscription if any
prettyProductName string system Pretty name of the Product for this subscription if any
prettyPlanName string system Pretty name of the Plan for this subscription if any
prettyPhaseName string system Pretty name of the PlanPhase for this subscription if any
prettyUsageName string system Pretty name of the Usage section for this subscription if any
itemType string system Item type (see below)
description string user or system Optional description of the item
startDate date user or system Start date of the period invoiced
endDate date user or system End date of the period invoiced
amount number user or system Amount being invoiced
rate number user or system Rate associated with the Plan
currency string user or system Currency associated with the account
quantity number system Quantity of usage blocks (number of units/block size). Applicable only for itemType=USAGE and when org.killbill.invoice.item.result.behavior.mode=DETAIL is specified
itemDetails string system JSON list correpsonding to usage items being invoiced. It contains one entry per tier
catalogEffectiveDate DateTime system The effective date of the underlying catalog. Applicable only for itemType=RECURRING
childItems list user or system In the hierarchical model, the items for the children.
auditLogs array system Array of audit log records for this invoice item

linkedInvoiceItemId: This ID is used to link to another item. For example, an item representing an adjustment would link to the item being adjusted.

itemType: The following invoice item types are currently supported:

  • EXTERNAL_CHARGE: Charge independent of any subscription state - typically added using invoice APIs.
  • FIXED: Fixed (one-time) charge associated with a subscription.
  • RECURRING: Recurring charge associated with a subscription.
  • REPAIR_ADJ: Internal adjustment generated by the system, used for billing in advance when the subscription state changed.
  • CBA_ADJ: Credit (positive or negative) generated by the system.
  • ITEM_ADJ: Invoice item adjustment - Typically generated by an operator and associated with a refund.
  • USAGE: Usage charge associated with a subscription
  • TAX: Tax item.
  • PARENT_SUMMARY: In the hierarchical model, represents the summary across all children

Refer to the Subscription Billing document for further details.

Custom Fields

Custom fields are {key, value} attributes that can be attached to any customer resource. In particular, they can be added to invoice items. For details on Custom Fields see Custom Field.

Add custom fields to an invoice item

Adds one or more custom fields to an invoice item. Existing custom fields are not disturbed.

HTTP Request

POST http://127.0.0.1:8080/1.0/kb/invoiceItems/{invoiceItemId}/customFields

Request Body

A list of Custom Field objects. Each object should specify at least the name and value attribute. For example:

[ { "name": "CF1", "value": "123" } ]

Query Parameters

None.

Response

If successful, returns a 201 status code. In addition, a Location header is returned with the URL to retrieve the custom fields associated with the invoice item.

Example Request:

curl -v \
    -X POST \
    -u admin:password \
    -H "X-Killbill-ApiKey: bob" \
    -H "X-Killbill-ApiSecret: lazar" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H "X-Killbill-CreatedBy: demo" \
    -H "X-Killbill-Reason: demo" \
    -H "X-Killbill-Comment: demo" \
    -d '[ { "objectType": "INVOICE_ITEM", "name": "Test Custom Field", "value": "demo_test_value" }]' \
    "http://127.0.0.1:8080/1.0/kb/invoiceItems/b52528dc-3a5c-4fde-93e3-ccf3585869de/customFields"   

Retrieve invoice item custom fields

Retrieve the custom fields associated with an invoice item

HTTP Request

GET http://127.0.0.1:8080/1.0/kb/invoiceItems/{invoiceItemId}/customFields

Query Parameters

Name Type Required Default Description
audit string no "NONE" Level of audit information to return:"NONE", "MINIMAL" (only inserts), or "FULL"

Response

If successful, returns a status code of 200 and a (possibly empty) list of custom field objects.

Example Request:

curl -v \
    -u admin:password \
    -H "X-Killbill-ApiKey: bob" \
    -H "X-Killbill-ApiSecret: lazar" \
    -H "Accept: application/json" \
    "http://127.0.0.1:8080/1.0/kb/invoiceItems/b52528dc-3a5c-4fde-93e3-ccf3585869de/customFields"

Example Response:

[
  {
    "customFieldId": "5fa2c86e-9a13-4acf-a996-7827549ed7df",
    "objectId": "b52528dc-3a5c-4fde-93e3-ccf3585869de",
    "objectType": "INVOICE_ITEM",
    "name": "Test Custom Field",
    "value": "demo_test_value",
    "auditLogs": []
  }
]

Modify custom fields for an invoice item

Modify the custom fields associated with an invoice item. Note that it is not possible to modify the name of a custom field, it is only possible to modify its value.

HTTP Request

PUT http://127.0.0.1:8080/1.0/kb/invoiceItem/{invoiceItemId}/customFields

Requst Body

A list of Custom Field objects specifying the id and the new value for the custom fields to be modified. Each object should specify at least the customFieldId and value attribute. For example:

[ { "customFieldId": "6d4c073b-fd89-4e39-9802-eba65f42492f", "value": "123" } ]

Although the fieldName and objectType can be specified in the request body, these attributes cannot be modified, only the value can be modified.

Query Parameters

None.

Response

If successful, returns a status code of 204 and an empty body.

Example Request:

curl -v \
    -X PUT \
    -u admin:password \
    -H "X-Killbill-ApiKey: bob" \
    -H "X-Killbill-ApiSecret: lazar" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H "X-Killbill-CreatedBy: demo" \
    -H "X-Killbill-Reason: demo" \
    -H "X-Killbill-Comment: demo" \
    -d '[ { "customFieldId": "5fa2c86e-9a13-4acf-a996-7827549ed7df", "value": "new value" }]' \
    "http://127.0.0.1:8080/1.0/kb/invoiceItems/b52528dc-3a5c-4fde-93e3-ccf3585869de/customFields"   

Remove custom fields from invoice item

Delete one or more custom fields from an invoice item. It accepts query parameters corresponding to the custom field ids to be deleted. If no query parameters are specified, it deletes all the custom fields corresponding to the invoice item.

HTTP Request

DELETE http://127.0.0.1:8080/1.0/kb/invoiceItems/{invoiceItemId}/customFields

Query Parameters

Name Type Required Default Description
customField string yes none Custom field ID that should be deleted. Multiple custom fields can be deleted by specifying a separate customField parameter corresponding to each field

Response

If successful, returns a status code of 204 and an empty body.

Example Request:

curl -v \
    -X DELETE \
    -u admin:password \
    -H "X-Killbill-ApiKey: bob" \
    -H "X-Killbill-ApiSecret: lazar" \
    -H "X-Killbill-CreatedBy: demo" \
    -H "X-Killbill-Reason: demo" \
    -H "X-Killbill-Comment: demo" \
    "http://127.0.0.1:8080/1.0/kb/invoiceItems/b52528dc-3a5c-4fde-93e3-ccf3585869de/customFields?customField=5fa2c86e-9a13-4acf-a996-7827549ed7df"

Tags

See Tags for an introduction to tags.

Note: None of the system tags are applicable for invoice items, only a user tag can be associated with an invoice item.

Add tags to invoice item

This API adds one or more tags to an invoice item. The tag definition corresponding to the tag being added must already exist.

HTTP Request

POST http://127.0.0.1:8080/1.0/kb/invoiceItems/{invoiceItemId}/tags

Request Body

A JSON array containing one or more tag definition ids to be added as tags.

Query Parameters

None.

Returns

If successful, returns a 201 status code. In addition, a Location header is returned containing the URL to retrieve the tags associated with the invoice item.

Example Request:

curl -v \
    -X POST \
    -u admin:password \
    -H "X-Killbill-ApiKey: bob" \
    -H "X-Killbill-ApiSecret: lazar" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H "X-Killbill-CreatedBy: demo" \
    -H "X-Killbill-Reason: demo" \
    -H "X-Killbill-Comment: demo" \
    -d '[ "2c1f8309-24d7-437c-971b-7e68ff2d393a"]' \
    "http://127.0.0.1:8080/1.0/kb/invoiceItems/b52528dc-3a5c-4fde-93e3-ccf3585869de/tags"   

Retrieve invoice item tags

Retrieve all tags attached to this invoice item.

HTTP Request

GET http://127.0.0.1:8080/1.0/kb/invoiceItems/{invoiceItemId}/tags

Query Parameters

Name Type Required Default Description
accountId string yes none Account ID
includedDeleted boolean no false If true, include deleted tags
audit string no "NONE" Level of audit information to return: "NONE", "MINIMAL" (only inserts), or "FULL"

Response

If successful, returns a status code of 200 and a list of tag objects.

Example Request:

curl -v \
    -u admin:password \
    -H "X-Killbill-ApiKey: bob" \
    -H "X-Killbill-ApiSecret: lazar" \
    -H "Accept: application/json" \
    "http://127.0.0.1:8080/1.0/kb/invoiceItems/480963fe-510f-45ef-afcd-0334806510b8/tags?accountId=b34b25b0-1be9-48f1-94a7-3f73f2b33070"    

Example Response:

[
  {
    "tagId": "4db8951f-97cd-4f5c-87a5-083d5a5f7770",
    "objectType": "INVOICE_ITEM",
    "objectId": "480963fe-510f-45ef-afcd-0334806510b8",
    "tagDefinitionId": "2c1f8309-24d7-437c-971b-7e68ff2d393a",
    "tagDefinitionName": "subscription_item",
    "auditLogs": []
  }
]

Remove tags from invoice item

This API deletes one or more tags attached to an invoice item.

HTTP Request

DELETE http://127.0.0.1:8080/1.0/kb/invoiceItems/{invoiceItemId}/tags

Query Parameters

Name Type Required Default Description
tagDef array of string yes none A tag definition ID identifying the tag that should be removed. Multiple tags can be deleted by specifying a separate tagDef parameter corresponding to each tag.

Response

If successful, returns a status code of 204 and an empty body.

Example Request:

curl -v \
    -X DELETE \
    -u admin:password \
    -H "X-Killbill-ApiKey: bob" \
    -H "X-Killbill-ApiSecret: lazar" \
    -H "X-Killbill-CreatedBy: demo" \
    -H "X-Killbill-Reason: demo" \
    -H "X-Killbill-Comment: demo" \
    "http://127.0.0.1:8080/1.0/kb/invoiceItems/480963fe-510f-45ef-afcd-0334806510b8/tags?tagDef=2c1f8309-24d7-437c-971b-7e68ff2d393a"   

Audit Logs

Audit logs provide a record of events that occur involving various specific resources. For details on audit logs see Audit and History.

Retrieve invoice item audit logs with history by invoice item id

Retrieve a list of audit log records showing events that occurred involving changes to a specified invoice item. History information (a copy of the full invoice item object) is included with each record.

Some examples:

  • Assuming this API is invoked with an invoice item id as soon as the invoice is generated, it would return:
    • An INSERT record corresponding to the invoice item creation
  • Assuming a CBA_ADJ invoice item is deleted, and this API is invoked with the CBA_ADJ invoice item id, this API would return two records:
    • An INSERT record corresponding to the invoice item creation
    • An UPDATE record corresponding to the invoice item deletion

HTTP Request

GET http://127.0.0.1:8080/1.0/kb/invoiceItems/{invoiceItemId}/auditLogsWithHistory

Query Parameters

None.

Response

If successful, returns a status code of 200 and a list of audit logs with history.

Example Request:

curl \
    -u admin:password \
    -H "X-Killbill-ApiKey: bob" \
    -H "X-Killbill-ApiSecret: lazar" \
    -H "Accept: application/json" \
    "http://127.0.0.1:8080/1.0/kb/invoiceItems/b45ef2ac-e4b7-4e79-89d8-1c2e95838300/auditLogsWithHistory"

Example Response:

[
  {
    "changeType": "INSERT",
    "changeDate": "2019-02-22T22:38:10.000Z",
    "objectType": "INVOICE_ITEM",
    "objectId": "b45ef2ac-e4b7-4e79-89d8-1c2e95838300",
    "changedBy": "SubscriptionBaseTransition",
    "reasonCode": null,
    "comments": null,
    "userToken": "1f03e074-dea1-45c5-aee3-c9464886f476",
    "history": {
      "id": null,
      "createdDate": "2019-02-22T22:38:10.000Z",
      "updatedDate": null,
      "recordId": 2698,
      "accountRecordId": 10,
      "tenantRecordId": 1,
      "type": "RECURRING",
      "invoiceId": "d456a9b3-7e48-4f56-b387-1d65a492e75e",
      "accountId": "7b3e14b1-6e76-46d3-bbfd-5a16e5b5eca2",
      "childAccountId": null,
      "bundleId": "d1b329c7-7dcf-466c-aaca-47bff304dab0",
      "subscriptionId": "70b6856e-6938-495f-9ae9-0a8ec0571c37",
      "description": "foo-monthly-evergreen",
      "productName": "Foo",
      "planName": "foo-monthly",
      "phaseName": "foo-monthly-evergreen",
      "usageName": null,
      "startDate": "2019-02-22",
      "endDate": "2019-03-22",
      "amount": 10,
      "rate": 10,
      "currency": "USD",
      "linkedItemId": null,
      "quantity": null,
      "itemDetails": null,
      "tableName": "INVOICE_ITEMS",
      "historyTableName": "INVOICE_ITEM_HISTORY"
    }
  }
]