# Upsert an invoice

Creates or updates (upserts) an invoice with a specified ID.

Endpoint: PUT /invoices/{id}
Version: latest
Security: SecretApiKey, JWT

## Path parameters:

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

## Request fields (application/json):

  - `websiteId` (string, required)
    ID of the website.
A website is where an organization obtains a customer.
For more information, see [Obtain an organization ID and website ID](https://www.rebilly.com/docs/settings/organizations-and-websites/#obtain-your-organization-id-and-website-id).

  - `currency` (string, required)
    Currency code in ISO 4217 format.

  - `shipping` (object) — one of (discriminator: calculator):
    Shipping settings.
    - manual:
      - `amount` (number, required)
        Shipping amount.
      - `calculator` (string, required)
        Shipping calculator.
        Enum: "manual"
    - rebilly:
      - `calculator` (string, required)
        Shipping calculator.
        Enum: "rebilly"
      - `rateId` (string,null)
        ID of the shipping rate.
If this value is not set,
the cheapest applicable shipping rate is used.
        Example: "shipping-123-456"

  - `tax` (object) — one of (discriminator: calculator):
    Taxes.
    - manual:
      - `calculator` (string, required)
        Type of tax calculator.
        Enum: same as `calculator` in "manual" (1 values)
      - `items` (array, required)
        Taxes applied.
      - `items.amount` (number, required)
        Amount of the tax.
      - `items.description` (string, required)
        Description of the tax.
    - rebilly-taxjar:
      - `calculator` (string, required)
        Type of tax calculator.
        Enum: "rebilly-taxjar"
      - `items` (array)
        Taxes applied and calculated based on the taxCategoryId of the related product.
      - `items.amount` (number, required)
        Amount of the tax.
      - `items.description` (string, required)
        Description of the tax.
    - rebilly-avalara:
      - `calculator` (string, required)
        Type of tax calculator.
        Enum: "rebilly-avalara"
      - `items` (array)
        Taxes applied and calculated based on the taxCategoryId of the related product.
      - `items.amount` (number, required)
        Amount of the tax.
      - `items.description` (string, required)
        Description of the tax.

  - `organizationTaxIdNumber` (object,null)
    Organization tax ID number that is displayed on the invoice.

  - `organizationTaxIdNumber.type` (string, required)
    Type of the tax ID number.
    Enum: "eu-vat", "other"

  - `organizationTaxIdNumber.value` (string, required)
    Value of the tax ID number.
    Example: "GB980780684"

  - `customerTaxIdNumber` (object,null)
    Customer tax ID number that is displayed on the invoice.

  - `customerTaxIdNumber.type` (string, required)
    Type of the tax ID number.
    Enum: same as `organizationTaxIdNumber.type` (2 values)

  - `customerTaxIdNumber.value` (string, required)
    Value of the tax ID number.
    Example: "GB980780684"

  - `billingAddress` (object)
    Billing address of the invoice.
After the first payment is made for an invoice, this value cannot be changed.

  - `billingAddress.firstName` (string,null)
    Contact's first name.
    Example: "Benjamin"

  - `billingAddress.lastName` (string,null)
    Contact's last name.
    Example: "Franklin"

  - `billingAddress.organization` (string,null)
    Contact's organization.
    Example: "Rebilly"

  - `billingAddress.address` (string,null)
    First line of the contact's street address.
    Example: "36 Craven St"

  - `billingAddress.address2` (string,null)
    Second line of the contact's street address.

  - `billingAddress.city` (string,null)
    Contact's city of residence.
    Example: "Austin"

  - `billingAddress.region` (string,null)
    Contact's region of residence.
    Example: "Texas"

  - `billingAddress.country` (string,null)
    Contact's country of residence in ISO 3166 alpha-2 country code.
For examples, see [ISO.org](https://www.iso.org/obp/ui/#search/code/).
    Example: "GB"

  - `billingAddress.postalCode` (string,null)
    Contact's postal code.
    Example: "WC2N 5NF"

  - `billingAddress.phoneNumbers` (array)
    List of phone numbers associated with the contact.

  - `billingAddress.phoneNumbers.label` (string, required)
    Phone number label or name.
    Example: "main"

  - `billingAddress.phoneNumbers.value` (string, required)
    Phone number value.
    Example: "1-512-777-0269"

  - `billingAddress.phoneNumbers.primary` (boolean)
    Specifies if the phone number is the contact's primary phone number.
    Example: true

  - `billingAddress.emails` (array)
    List of email addresses associated with the contact.

  - `billingAddress.emails.label` (string, required)
    Email label or name.
    Example: "main"

  - `billingAddress.emails.value` (string, required)
    Email address value.
    Example: "rebilly@example.com"

  - `billingAddress.emails.primary` (boolean)
    Specifies if the email address is the contact's primary email address.
    Example: true

  - `billingAddress.dob` (string,null)
    Contact's date of birth in ISO-8601 YYYY-MM-DD format.
    Example: "1980-04-01"

  - `billingAddress.jobTitle` (string,null)
    Contact's job title.
    Example: "CEO"

  - `deliveryAddress` (object)
    Delivery address of the invoice.

  - `poNumber` (string,null)
    Purchase order number that is displayed on the invoice.
    Example: "PO123456"

  - `notes` (string)
    Notes for the customer that are displayed on the invoice.

  - `autopayScheduledTime` (string,null)
    Date and time when an automatic payment (autopay) is scheduled.

  - `dueTime` (string)
    Date and time when the invoice is due for payment.

  - `customerId` (string, required)
    ID of the customer resource.
    Example: "cus_0YV7DDSDD1C8DA64KHH2W33CPF"

  - `retryInstruction` (object,null)
    Invoice payment retry instruction.
This object specifies how to proceed if a payment related to the invoice fails.

  - `retryInstruction.attempts` (array, required)
    Describes the retry instruction.

  - `retryInstruction.attempts.scheduleInstruction` (object, required) — one of (discriminator: method):
    Specifies when the payment retry instruction is performed.
    - date-interval:
      - `method` (string, required)
        Enum: "date-interval"
      - `duration` (integer, required)
        Number of time units.
      - `unit` (any, required)
        Unit of time.
      - `anchor` (object) — one of (discriminator: method):
        Instruction for calculating the period anchor.
        - day-of-month:
          - `method` (string, required)
            Enum: "day-of-month"
          - `day` (integer, required)
            Day of the month in which the event occurs.
If the month has less days, the last day of the month is selected.
          - `time` (string)
            Extended ISO-8601 format of time.
        - day-of-week:
          - `method` (string, required)
            Enum: "day-of-week"
          - `day` (string, required)
            Day of the week when the event occurs.
            Enum: "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
          - `week` (string, required)
            Enum: "next", "first-in-month", "last-in-month"
          - `time` (string)
            Extended ISO-8601 format of time.
    - day-of-month:
      - `method` (string, required)
        Enum: same as `method` in "day-of-month" (1 values)
      - `day` (integer, required)
        Day of the month in which the event occurs.
If the month has less days, the last day of the month is selected.
      - `time` (string)
        Extended ISO-8601 format of time.
    - day-of-week:
      - `method` (string, required)
        Enum: same as `method` in "day-of-week" (1 values)
      - `day` (string, required)
        Day of the week when the event occurs.
        Enum: same as `day` in "day-of-week" (7 values)
      - `week` (string, required)
        Enum: same as `week` in "day-of-week" (3 values)
      - `time` (string)
        Extended ISO-8601 format of time.
    - immediately:
      - `method` (string, required)
        Enum: "immediately"
    - intelligent:
      - `method` (string, required)
        Enum: "intelligent"
      - `duration` (integer, required)
        Latest point in time at which the event should occur.
The event occurs at a random time between the initial time and duration time.
      - `unit` (any, required)
        Unit of time.

  - `retryInstruction.attempts.amountAdjustmentInstruction` (object) — one of (discriminator: method):
    Specifies if the payment amount must be adjusted for the retry.
    - partial:
      - `method` (string, required)
        Enum: "partial"
      - `value` (number, required)
        Amount of the payment.
      - `type` (string, required)
        Payment amount type.
        Enum: "percent", "fixed"
      - `afterApprovalPolicy` (any) — one of (discriminator: method):
        After an approved payment retry for an adjusted amount, this field specifies whether to discount the remaining invoice amount.
        - none:
          - `method` (string, required)
            No payment amount adjustment.
            Enum: "none"
        - discount-amount-remaining:
          - `method` (string, required)
            Discount the remaining amount on the invoice.
            Enum: "discount-amount-remaining"
    - none:
      - `method` (string, required)
        Enum: same as `method` in "none" (1 values)

  - `retryInstruction.attempts.tryBackupInstruments` (boolean)
    Specifies whether to use backup payment instruments on an invoice payment retry.

  - `retryInstruction.afterAttemptPolicies` (array, required)
    Describes the action to take when a payment attempt concludes, and payment is not collected.
    Enum: "change-subscription-renewal-time"

  - `retryInstruction.afterRetryEndPolicies` (array, required)
    Describes the action to take when all scheduled payment retries, in a retry instruction, have concluded and payment is not collected.
    Enum: "abandon-invoice", "cancel-subscription"

  - `delinquencyTime` (string,null)
    Date and time when the related order is considered delinquent, and is canceled.
If this value is null, no delinquency time is configured.
If the dueTime of the order becomes greater than the delinquencyTime value,
the delinquencyTime value becomes equal to dueTime.

If an invoice is not related to an order, this field can only be null.

## 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 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 404 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 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.

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

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

## 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.


