# Update an order item

Updates an order item.
This is an experimental endpoint and may be changed or removed in the future.

Endpoint: PATCH /orders/{id}/items/{itemId}
Version: latest
Security: SecretApiKey, JWT

## Security:

  - `SecretApiKey` (unknown)
    apiKey in header REB-APIKEY

  - `JWT` (unknown)
    http bearer JWT

## Path parameters:

  - `id` (string, required)
    ID of the resource.

  - `itemId` (string, required)
    ID of the order item.

## Request body:

  - `application/json` (unknown)
    Update item request.

## Request fields (application/json):

  - `quantityFilled` (number | null)
    Filled quantity of the subscription item.
    Example: 5.125

  - `excludeFromMrr` (boolean)
    Specifies if this item should be excluded from monthly recurring revenue calculations.

  - `plan` (object)
    Details of the subscription item plan.

  - `plan.productOptions` (object | null)
    Name-value pairs that specify the product options.
    Example: {"color":"red","size":"xxl"}

## Response 200:

  - `200` (unknown)
    Order item updated.

## Response 200 fields (application/json):

  - `id` (string)
    ID of the order item.

  - `planId` (string)
    ID of the plan.
> **Note:** This field is deprecated. Use the `plan.id` field instead.
    Example: plan_0YV7DENSVGDBW9S71XZNNYYQ0X

  - `quantity` (integer)
    Number of product units in the specified plan.

  - `quantityFilled` (number | null)
    Number of filled product units.
    Example: 5.125

  - `plan` (any, required)

  - `plan.id` (string, required)
    Unique resource ID.
    Example: 4f6cf35x-2c4y-483z-a0a9-158621f77a21

  - `plan.id` (string, required)
    ID of the plan.
    Example: plan_0YV7DENSVGDBW9S71XZNNYYQ0X

  - `plan.type` (string)
    Variant of the plan.
This field is optional in create and update requests.
The variant is `one-time-sale` when both `recurringInterval` and `trial` are omitted.
If included, this field must match the applicable variant.
A mismatch results in an HTTP `422` response.
Responses always include this field.
    Enum: "one-time-sale"

  - `plan.name` (string, required)
    Name of the plan.
This name is displayed on invoices and receipts.

  - `plan.description` (string)
    Plain-text description of the plan.
This field accepts plain-text only.

  - `plan.richDescription` (string)
    Rich-text description of the plan.
This field accepts rich text formatting, such as: bold, underline, italic, and hyperlinks.

  - `plan.productId` (string, required)
    ID of the related product.
    Example: prod_0YV7DES3WPC5J8JD8QTVNZBZNZ

  - `plan.productOptions` (object | null)
    Name-value pairs that specify the product options.
    Example: {"color":"red","size":"xxl"}

  - `plan.currency` (string, required)
    Currency code in ISO 4217 format.
    Example: USD

  - `plan.currencySign` (string)
    Currency sign.

  - `plan.pricing` (object, required)
    Pricing details.

  - `plan.pricing.formula` (string, required)
    Price formula that determines which algorithm is used to calculate the invoice price based on the following factors:
- Quantity in the order.
This value may be variable if you are charging based on usage.
If you are not charging based on usage,
this value is determined when an order is created.
- Price of the quantity range.
Some formulas set a price based on defined product quantity ranges.

For more information, see [Price formulas](https://www.rebilly.com/docs/billing/pricing-formulas/).
    Enum: "fixed-fee"

  - `plan.pricing.price` (number, required)
    Use this formula to charge for subscriptions that have a fixed price,
number of units, and reoccur over a fixed period of time,
such as every: day, week, month, year, or number of years.
For example, a streaming company charges customers $13.99 each month for subscription period that is 6 months in duration.
The quantity of movies that a customer streams each month does not impact the price.
    Example: 99.95

  - `plan.pricing.price` (number, required)
    Use this formula to charge a flat fee per unit.
For example, $0.10 for each transaction or $4 per unit.
If the value of this field is `0`, the product is free.
    Example: 99.95

  - `plan.pricing.minQuantity` (integer | null)
    Minimum permitted unit quantity.
If this value is `null`, no limit is in place.
    Example: 1

  - `plan.pricing.maxQuantity` (integer | null)
    Maximum permitted unit quantity.
If this value is `null`, no limit is in place.
    Example: 1

  - `plan.pricing.brackets` (array, required)
    Use this formula to charge for units that are sold in specific quantity ranges.
For example, a bank charges a merchant based on the number of transactions they complete each month.
| Price total | Max quantity | Description |
|  --- | --- | --- |
| $50 | 1000 | Up to 1000 transactions |
| $100 | 1500 | Between 1000 and 1500 transactions |
| $200 | 3000 | Between 1500 and 3000 transactions |
| $500 | null | More than 3000 transactions |

- If the merchant completes 900 transaction in a month, they are charged $50.
- If the merchant completes 1001 transaction in a month, they are charged $100.
- If the merchant completes 2500  transaction in a month, they are charged $200.
- If the merchant completes more than 3000 transaction in a month, they are charged $500.

  - `plan.pricing.brackets.price` (number)
    Price of the quantity range.
If the value of this field is `0`, the product is free.
    Example: 99.95

  - `plan.pricing.brackets.maxQuantity` (integer | null)
    Maximum permitted unit quantity.
If this value is `null`, no limit is in place.
This value starts from the end of the previous quantity range.
If there are no previous quantity ranges,
this value starts at 1.
    Example: 1

  - `plan.pricing.brackets` (array, required)
    Use this formula to charge for units that are sold within defined quantity ranges, or tiers.
If a customer buys a number of units that span more than one tier,
the total cost is calculated based on the cost of the units in each tier.
For example, a software company sells user licenses based on the following:
| Tier | Price per user | Max quantity | Description |
|  --- | --- | --- | --- |
| 1 | $40 | 3 | 1 to 3 user licenses |
| 2 | $30 | 5 | 5 to 8 user licenses |
| 3 | $15 | null | 9 or more user licenses |

If a customer buys 10 user licenses, the pricing is as follows:
- 3 licenses at tier 1 (3 x $40) is 120
- 5 licenses at tier 2 (5 x $30) is 150
- 2 licenses at tier 3 (2 x $15) is 30

Total cost = $330
Formula: `(price for the tier x quantity within the tier)` + `(price for next tier x quantity in next tier)` + `...` = final price.

  - `plan.pricing.brackets` (array, required)
    Use this formula to charge for units that are sold in bulk, or volume ranges.
This formula enables customers to pays less per unit when they buy a large volume of units.
Unit cost is based on the highest volume range, and does not include lower volume range pricing.
For example, a company sells t-shirts in the following volume ranges:
| Price per unit | Max quantity | Description |
|  --- | --- | --- |
| $10 | 1 | 1 t-shirt |
| $8 | 5 | 2 to 5 t-shirts |
| $4 | null | 6 or more t-shirts |

- If a customer buys 1 unit, they pay $10.
- If a customer buys 3 units, they pay $24 per unit, which is $8 per unit.
- If a customer buys 10 units, they pay $40, which is $4 per unit.

  - `plan.setup` (object | null)
    Setup fee information for the plan.

  - `plan.setup.price` (number, required)
    One-time setup fee charged when the plan starts.
This field is deprecated.
Use the `setupFee` field instead.

  - `plan.setupFee` (number | null)
    One-time setup fee charged when the plan starts.
Set to `0` or `null` if no setup fee applies.
    Example: 0

  - `plan.customFields` (object)
    Use custom fields to extend a resource scheme to include custom data that is not provided as a common field.
For more information, see [Custom fields](https://www.rebilly.com/catalog/all/custom-fields).
    Example: {"foo":"bar"}

  - `plan.isActive` (boolean)
    Specifies if the plan is active.

  - `plan.revision` (integer)
    Number of times the plan is modified.
Compare this value with materialized subscription item revision values.

  - `plan.isTrialOnly` (boolean)
    Specifies if a plan is a trial that does not have recurring instructions.

  - `plan.recurringInterval` (null)
    Service interval settings.

  - `plan.trial` (null)
    Trial configuration setting.

  - `plan.createdTime` (string)
    Date and time when the resource is created.
This value is set automatically when the resource is created.

  - `plan.updatedTime` (string)
    Date and time when the resource is updated.
This value is set automatically when the resource is updated.

  - `plan._links` (array)
    Related links.

  - `plan._links.href` (string)
    Link URL.

  - `plan._links.rel` (string)
    Type of link.
    Enum: "self", "attachments"

  - `plan.type` (string)
    Variant of the plan.
This field is optional in create and update requests.
The variant is `subscription` when `recurringInterval` is present.
If included, this field must match the applicable variant.
A mismatch results in an HTTP `422` response.
Responses always include this field.
    Enum: "subscription"

  - `plan.trial` (object | null)

  - `plan.trial.price` (number, required)
    Price of setting up a trial.
If your service charges a fee for a trial, specify it here.
To charge no trial fee, set this value to `0`.

  - `plan.trial.period` (object, required)
    Period information.

  - `plan.trial.period.unit` (string, required)
    Unit of time.
    Enum: "day", "week", "month", "year"

  - `plan.trial.period.length` (integer, required)
    Length of time.

  - `plan.meteredBilling` (object | null)
    Use metered billing when an exact quantity is unknown.
Report usage during a service period and charge customers afterwards.
Metered billing plans must be postpaid.

  - `plan.meteredBilling.strategy` (string, required)
    Enum: "sum", "last"

  - `plan.meteredBilling.min` (number | null)
    Minimum quantity that is charged at the end of a service period regardless of reported usage.

  - `plan.meteredBilling.max` (number | null)
    Maximum quantity that is charged at the end of a service period regardless of reported usage.

  - `plan.meteredBilling.sticky` (boolean)
    When enabled, if no usage is reported during a service period,
the plan bills the last known reported quantity from a previous period instead of zero.
This is suitable for hosted or persistent resources whose usage does not change every period.
Only supported with `strategy`: `last`.
    Example: false

  - `plan.invoiceTimeShift` (object | null)
    Use invoice time shift to control the billing time.
Invoice time shift adjusts the invoice issue and due date when billing must occur before the service period changes.
Use invoice time shift in conjunction with `billingTiming` to:
- Bill immediately when the service period starts.
- Bill immediately after the service period ends.
- Bill at an interval of time before the service period starts.
- Bill at an interval of time after the service period starts.
- Bill at an interval of time before the service period ends.
- Bill at an interval of time after the service period ends.

  - `plan.invoiceTimeShift.issueTimeShift` (object)
    Calculation instruction of the billing time.
This is used in conjunction with the service period anchor to calculate
the time at which the invoice is issued. For more information, see
[Service period anchor, billing timing, and invoice time shift](https://www.rebilly.com/docs/dev-docs/subscriptions#service-period-anchor-billing-timing-and-invoice-time-shift).

  - `plan.invoiceTimeShift.issueTimeShift.chronology` (string, required)
    Sequential order of the billing time relative to the start of the service period.
    Enum: "before"

  - `plan.invoiceTimeShift.issueTimeShift.duration` (integer, required)
    Amount of time by which to move the invoice issue time or date.

  - `plan.invoiceTimeShift.issueTimeShift.unit` (any, required)
    Unit of time.

  - `plan.invoiceTimeShift.dueTimeShift` (object)
    Calculation instruction of the invoice due time.
This is used in conjunction with the service period anchor to calculate when
an invoice is due for payment. For more information, see
[Service period anchor, billing timing, and invoice time shift](https://www.rebilly.com/docs/dev-docs/subscriptions#service-period-anchor-billing-timing-and-invoice-time-shift).
The sequential order of due time shift is always after the due date.

  - `plan.invoiceTimeShift.dueTimeShift.duration` (integer, required)
    Amount of time by which to move the invoice due time or date.

  - `plan.invoiceTimeShift.dueTimeShift.unit` (any, required)
    Unit of time.

  - `plan.type` (string)
    Variant of the plan.
This field is optional in create and update requests.
The variant is `trial-only` when `trial` is present without `recurringInterval`.
If included, this field must match the applicable variant.
A mismatch results in an HTTP `422` response.
Responses always include this field.
    Enum: "trial-only"

  - `plan.trial` (object | null, required)
    Trial configuration settings.

  - `usageLimits` (any)

  - `usageLimits.softLimit` (object)
    Defines thresholds for notification purposes.
For example, to notify the customer that their usage is near the hard limit of their metered billing plan.
This notification informs the customer so that they can upgrade their plan before the hard limit is reached.
When metered usage equals or exceeds the configured soft limit, the `soft-usage-limit-reached` event is triggered.
The quantity limit applies to the larger of the reported and billed quantity.
If a minimum billable quantity results in a billed quantity that is higher than the reported quantity, the billed quantity applies to the limit.
If a maximum billable quantity results in a billed quantity that is lower than the reported quantity, the reported quantity applies to the limit.
The amount limit applies to the billed amount.
To notify the customer, a webhook and notification can be configured for this event.
This field is useful for accounting and customer success purposes.
The usage of metered billing plans can still be reported if the soft limit is reached.

  - `usageLimits.softLimit.quantity` (integer)
    Usage limit quantity.

  - `usageLimits.softLimit.amount` (number)
    Usage limit amount in the currency of the order.

  - `usageLimits.hardLimit` (object)
    Defines a limit where the customer can no longer use the service.
Hard limits are used in addition to soft limits.
When a soft limit is reached,
a customer may receive a notification
but the service can still be provided up to the hard limit value so that the customer can upgrade their plan.
When the reported usage reaches the configured limit,
a specific event is triggered.
To notify the customer in the merchant system,
or block a service,
a webhook and notification can be configured for this event.
When the total usage reaches the hard limit quantity,
or amount values,
metered billing plan usages can no longer be reported.
Plans with a minimum quantity, fixed fee, or flat stairstep bracket set a minimum billable quantity and amount.
A `quantity` value below the minimum billable quantity is invalid.
An `amount` value below the minimum billable amount is invalid.
A `0` value remains valid even on plans with minimum billing.

  - `usageLimits.hardLimit.quantity` (integer)
    Usage limit quantity.

  - `usageLimits.hardLimit.amount` (number)
    Usage limit amount in the currency of the order.

  - `usageLimits.trialLimit` (any)
    Defines a usage cap during the trial period of a subscription.
This limit is enforced only while the subscription is in its trial phase.
When the reported usage reaches the configured trial limit, an event called 'trial-usage-limit-reached' is triggered.
To notify the customer or restrict access to the service, a webhook and notification can be configured for this event.
Once the trial limit is reached, additional usage cannot be reported unless the trial ends.
    Example: 20.725

  - `usageStatus` (any)

  - `usageStatus.isSoftLimitReached` (boolean)
    Specifies if the soft limit has been reached.
    Example: false

  - `usageStatus.isHardLimitReached` (boolean)
    Specifies if the hard limit has been reached.
    Example: false

  - `usageStatus.isTrialLimitReached` (boolean)
    Specifies if the trial limit has been reached.
    Example: false

  - `revision` (integer)
    Revision number that increments with each overriding change to this specific plan item.

  - `isModified` (boolean)
    Specifies if the plan information is modified for this subscription.

  - `isGrandfathered` (boolean)
    Specifies if the current plan revision number is greater than the plan item revision number.

  - `excludeFromMrr` (boolean)
    Specifies if this item should be excluded from monthly recurring revenue calculations.

  - `_embedded` (object)
    Embedded objects that are requested by the `expand` query parameter.

  - `_embedded.product` (object)

## Response 200 headers (application/json):

  - `Rate-Limit-Limit` (integer)
    Maximum number of requests available at one time for this rate limit.
For more information, see [Rate limits](#section/Rate-limits).
    Example: 500

  - `Rate-Limit-Remaining` (integer)
    Number of requests still available for this rate limit.
For more information, see [Rate limits](#section/Rate-limits).
    Example: 499

## Response 401:

  - `401` (unknown)
    Unauthorized access.
Invalid credentials used.

## Response 401 fields (application/json):

  - `status` (integer)
    HTTP status code.

  - `type` (string)
    Problem type in the form of a [URI](https://tools.ietf.org/html/rfc3986) reference.
It should provide human-readable documentation for the problem type.
When this member is not present, its value is assumed to be "about:blank".

  - `title` (string)
    Short, human-readable summary of the problem type.
Other than for the purposes of localization, this should not change from occurrence to occurrence of the problem.

  - `detail` (string)
    Human-readable explanation that is specific to this occurrence of the problem.

  - `instance` (string)
    URI reference that identifies the specific occurrence of the problem.
It may or may not yield further information if dereferenced.

## Response 403:

  - `403` (unknown)
    Access forbidden.
If the organization requires multi-factor authentication (MFA) and the session has not passed MFA, `error` is `mfa_required`.

## Response 403 fields (application/json):

  - `status` (integer)
    HTTP status code.

  - `error` (string)
    Message that describes why the request is forbidden.
Most responses use a descriptive message, such as `Not allowed to change security settings`.
If the organization requires multi-factor authentication (MFA) and MFA verification has not been completed for the session, this value is `mfa_required`.
If the request sets `requireMfa` to `true` and MFA verification has not been completed for the session, this value is `mfa_required_for_caller`.

  - `type` (string)
    Problem type in the form of a [URI](https://tools.ietf.org/html/rfc3986) reference.
It should provide human-readable documentation for the problem type.
When this member is not present, its value is assumed to be "about:blank".

  - `title` (string)
    Short, human-readable summary of the problem type.
Other than for the purposes of localization, this should not change from occurrence to occurrence of the problem.

  - `detail` (string)
    Human-readable explanation that is specific to this occurrence of the problem.

  - `instance` (string)
    URI reference that identifies the specific occurrence of the problem.
It may or may not yield further information if dereferenced.

## Response 422:

  - `422` (unknown)
    Invalid data sent.

## Response 422 fields (application/json):

  - `status` (integer)
    HTTP status code.

  - `type` (string)
    Problem type in the form of a [URI](https://tools.ietf.org/html/rfc3986) reference.
It should provide human-readable documentation for the problem type.
When this member is not present, its value is assumed to be "about:blank".

  - `title` (string)
    Short, human-readable summary of the problem type.
Other than for the purposes of localization, this should not change from occurrence to occurrence of the problem.

  - `detail` (string)
    Human-readable explanation that is specific to this occurrence of the problem.

  - `instance` (string)
    URI reference that identifies the specific occurrence of the problem.
It may or may not yield further information if dereferenced.

  - `invalidFields` (array)
    Invalid field details.
    Example: [{"field":"field1","message":"field1 is invalid"},{"field":"subObject.field2","message":"field2 is invalid"},{"field":"subObject.field2","message":"another error in the field2"}]

  - `invalidFields.field` (string)
    Name of the field.
Dot notation is used for nested object field names.

  - `invalidFields.message` (string)
    Message field.

## Response 429:

  - `429` (unknown)
    Request rate limit exceeded.

## Response 429 fields (application/json):

  - `type` (string)
    Problem type in the form of a [URI](https://tools.ietf.org/html/rfc3986) reference.
It should provide human-readable documentation for the problem type.
When this member is not present, its value is assumed to be "about:blank".
    Example: about:blank

  - `title` (string)
    Short, human-readable summary of the problem type.
Other than for the purposes of localization, this should not change from occurrence to occurrence of the problem.
    Example: Rate Limit Exceeded

  - `status` (integer)
    HTTP status code.

  - `detail` (string)
    Human-readable explanation that is specific to this occurrence of the problem.
    Example: A request cannot be executed because the user has sent too many requests within a certain period of time

  - `instance` (string)
    URI reference that identifies the specific occurrence of the problem.
It may or may not yield further information if dereferenced.

## Response 429 headers (application/json):

  - `Rate-Limit-Limit` (integer)
    Maximum number of requests available at one time for this rate limit.
For more information, see [Rate limits](#section/Rate-limits).
    Example: 500

  - `Rate-Limit-Remaining` (integer)
    Number of requests still available for this rate limit.
For more information, see [Rate limits](#section/Rate-limits).
    Example: 0

  - `Rate-Limit-Retry-After` (integer)
    Number of seconds to wait before retrying the request.
    Example: 1

  - `Retry-After` (integer)
    Number of seconds to wait before retrying the request.
    Example: 1

