> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tread.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Batch update InvoiceLineItems for an Invoice for a Company

> Batch update `InvoiceLineItems` for an `Invoice` for a `Company`.

This endpoint allows updating, creating, deleting `InvoiceLineItems` all at once.

If updating existing records:
- must provide the `id` for each record to be updated
- only provide the fields to be updated
- no need to provide the `rate_type` field
e.g.
```json
invoice_line_items: [
  {
    "id": "some-uuid"
    "quantity": 20.25,
    "rate": 15.75
  }
]
```

If deleting existing records:
- must provide the `id` and the property `_destroy: 1`

e.g. 
```json
invoice_line_items: [
  {
    "id": "some-uuid"
    "_destroy": 1
  }
]
```

<hr>

## This section is deprecated
#### We are still accepting `rate_type` but it will have no effect. It will be removed in one of the next releases.

If creating new records (for cases where the `Invoice` `rate_type` grouping changes):
- must provide the `rate_type`
- must not provide the `id` for each record to be created
- provide all the fields needed for the record
e.g.
```json
rate_type: "RatePerTon",
invoice_line_items: [
  {
    "quantity": 20.25,
    "rate": 12.5
  },
  {
    "quantity": 22.50,
    "rate": 12.5
  }
]
```



## OpenAPI

````yaml /api-reference/openapi.json patch /v1/companies/{company-id}/invoices/{invoice-id}/invoice_line_items
openapi: 3.0.3
info:
  title: Horizon API V1
  version: '1.0'
  contact:
    name: Tread
    url: https://tread.io
    email: developers@tread.io
  description: >-
    This is the Version 1 implementation.


    When in doubt we default to the practices outlined
    [here](https://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#advanced-queries)
  license:
    name: Private
    url: https://tread.io
servers:
  - description: production
    url: https://api.tread-horizon.com
security:
  - bearerAuth: []
tags:
  - name: Projects
  - name: Orders
  - name: Loads
  - name: Jobs
  - name: JobAssignments
  - name: ApprovalAssignments
  - name: Equipment
  - name: FuelSurcharges
  - name: Materials
  - name: Accounts
  - name: Tickets
  - name: Users
  - name: Sites
  - name: Companies
  - name: Departments
  - name: Rates
  - name: Services
  - name: EquipmentType
  - name: FileAttachments
  - name: MaterialType
  - name: LineItemType
  - name: DriverStateEvent
  - name: Authentication
  - name: IamRoles
  - name: Typeaheads
  - name: Integrations
  - name: Reflection
  - name: LoadCycles
  - name: AddOns
  - name: ServiceClass
  - name: Invoices
  - name: JobSummaries
  - name: LoadSummaries
  - name: CompanyShares
  - name: UserDevicePermission
  - name: Drivers
  - name: Settlements
  - name: LocationHistories
  - name: Telematics
  - name: OmniReports
  - name: DriverDays
  - name: Agave
  - name: AddOnCharges
  - name: ResourceUsageLogs
  - name: ResourceScopes
  - name: TravelledDistances
  - name: MaterialRates
  - name: CompanyDayJobStats
  - name: KMLFiles
  - name: AutoAddOnAssignments
  - name: SiteRateSchedules
  - name: TwilioIntegrations
  - name: Foremen
  - name: AccountExternalTruckIdentifier
  - name: GeofenceTriggers
  - name: Labels
  - name: Compliance
  - name: ComplianceDocuments
paths:
  /v1/companies/{company-id}/invoices/{invoice-id}/invoice_line_items:
    parameters:
      - schema:
          type: string
          format: uuid
        name: invoice-id
        in: path
        required: true
        description: Invoice ID
      - schema:
          type: string
          format: uuid
        name: company-id
        in: path
        required: true
        description: Company ID
      - $ref: '#/components/parameters/Accept-Language'
    patch:
      tags:
        - Invoices
      summary: Batch update InvoiceLineItems for an Invoice for a Company
      description: >-
        Batch update `InvoiceLineItems` for an `Invoice` for a `Company`.


        This endpoint allows updating, creating, deleting `InvoiceLineItems` all
        at once.


        If updating existing records:

        - must provide the `id` for each record to be updated

        - only provide the fields to be updated

        - no need to provide the `rate_type` field

        e.g.

        ```json

        invoice_line_items: [
          {
            "id": "some-uuid"
            "quantity": 20.25,
            "rate": 15.75
          }
        ]

        ```


        If deleting existing records:

        - must provide the `id` and the property `_destroy: 1`


        e.g. 

        ```json

        invoice_line_items: [
          {
            "id": "some-uuid"
            "_destroy": 1
          }
        ]

        ```


        <hr>


        ## This section is deprecated

        #### We are still accepting `rate_type` but it will have no effect. It
        will be removed in one of the next releases.


        If creating new records (for cases where the `Invoice` `rate_type`
        grouping changes):

        - must provide the `rate_type`

        - must not provide the `id` for each record to be created

        - provide all the fields needed for the record

        e.g.

        ```json

        rate_type: "RatePerTon",

        invoice_line_items: [
          {
            "quantity": 20.25,
            "rate": 12.5
          },
          {
            "quantity": 22.50,
            "rate": 12.5
          }
        ]

        ```
      operationId: patch-v1-companies-company-id-invoices-invoice-id-invoice_line_items
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rate_type:
                  $ref: '#/components/schemas/RateType'
                invoice_line_items:
                  type: array
                  x-stoplight:
                    id: 8binxtypupuut-company
                  items:
                    $ref: '#/components/schemas/InvoiceLineItem-Update'
      responses:
        '200':
          description: OK
          headers:
            Link:
              schema:
                type: string
              description: Contains prev and next links for pagination
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: array
                    x-stoplight:
                      id: d9v9xort2c4gg-company
                    items:
                      $ref: '#/components/schemas/InvoiceLineItem-Read'
        '400':
          $ref: '#/components/responses/Error'
        '401':
          $ref: '#/components/responses/UnauthenticatedError'
        '403':
          $ref: '#/components/responses/Error'
        '404':
          $ref: '#/components/responses/Error'
        '406':
          $ref: '#/components/responses/Error'
        '415':
          $ref: '#/components/responses/Error'
        '422':
          $ref: '#/components/responses/ModelError'
components:
  parameters:
    Accept-Language:
      name: Accept-Language
      in: header
      schema:
        type: string
        default: en
        example: en
      description: >-
        The Accept-Language request HTTP header indicates the natural language
        and locale that the client prefers. 
  schemas:
    RateType:
      title: RateType
      x-stoplight:
        id: zn2jb7gsifkk3
      enum:
        - RatePerHour
        - RatePerDay
        - RatePerLoad
        - RatePerTon
        - RatePerTonne
        - RatePerYard
        - RatePerBushel
        - RateCommission
        - RateFlatCommission
        - RateFlatRate
      example: RatePerHour
    InvoiceLineItem-Update:
      title: InvoiceLineItem-Update
      x-stoplight:
        id: bqeqs6grf9mkb
      allOf:
        - $ref: '#/components/schemas/Destroyable'
        - type: object
          properties:
            quantity:
              type: number
              x-stoplight:
                id: 7blob4b6rlg8z
            rate:
              type: number
              x-stoplight:
                id: erb5hyci036n8
            pay_start_time:
              type: string
              x-stoplight:
                id: kyf9icu2pmkx9
              format: date-time
              nullable: true
            pay_end_time:
              type: string
              x-stoplight:
                id: vsmc30j8j8t2n
              format: date-time
              nullable: true
            billing_adjustment_minutes:
              type: integer
              x-stoplight:
                id: o792d7cilq8g7
            load_id:
              type: string
              x-stoplight:
                id: yc4s45yy1dpx0
              format: uuid
    InvoiceLineItem-Read:
      title: InvoiceLineItem-Read
      x-stoplight:
        id: lbb9n9hfx009r
      allOf:
        - $ref: '#/components/schemas/Identifier'
        - type: object
          required:
            - quantity
            - total_amount
            - revenue_rate_value
            - revenue_cost_rate_type
            - billing_adjustment_minutes
            - pay_start_time
            - pay_end_time
            - invoice_id
            - name
            - delivered_quantity
            - line_item_type
            - rate
            - rate_type
            - material_rate_unit_of_measure
          properties:
            quantity:
              type: string
              x-stoplight:
                id: vja2bsq172org
            total_amount:
              type: string
              x-stoplight:
                id: fwmhuuc6afo05
            revenue_rate_value:
              type: string
              x-stoplight:
                id: w8kyneeororyn
              description: The revenue rate or sell price of the invoice line item
            revenue_cost_rate_type:
              $ref: '#/components/schemas/AddOnRateType'
            billing_adjustment_minutes:
              type: integer
              x-stoplight:
                id: 7kzoo1b5fjcua
            pay_start_time:
              type: string
              x-stoplight:
                id: 5hk8kdv3tf7fu
              format: date-time
              nullable: true
            pay_end_time:
              type: string
              x-stoplight:
                id: frlpnr1dsx6xk
              format: date-time
              nullable: true
            invoice_id:
              type: string
              x-stoplight:
                id: cxgoc5hzxs0hm
              format: uuid
            load:
              $ref: '#/components/schemas/Load-Read-Nested'
            name:
              type: string
              x-stoplight:
                id: p4gxwco1xm5f4
              nullable: true
            delivered_quantity:
              type: string
              x-stoplight:
                id: n36bkwjaot8f6
            line_item_type:
              $ref: '#/components/schemas/InvoiceLineItemType'
            rate:
              type: string
              x-stoplight:
                id: 17aohzilbnz8d
              deprecated: true
              description: Deprecated in favor of `revenue_rate_value`.
            rate_type:
              type: string
              x-stoplight:
                id: h454x8xipq8gm
              deprecated: true
              description: Deprecated in favor of `revenue_cost_rate_type`.
            material_rate_unit_of_measure:
              $ref: '#/components/schemas/NullableOrderUnitOfMeasure'
    Destroyable:
      title: Destroyable
      x-stoplight:
        id: 2uftzhptd2l14
      type: object
      properties:
        id:
          type: string
          x-stoplight:
            id: gx1ww996hmzqm
          format: uuid
          description: Required if `_destroy` is set
        _destroy:
          type: integer
          x-stoplight:
            id: 0xjwztkz4fmcr
          description: >-
            If this is provided with value of `1` like so `_destroy: 1` then
            this model will be deleted. The `id` must be set.
      additionalProperties: false
    Identifier:
      title: Identifier
      x-stoplight:
        id: gnd39lue5v7ol
      type: object
      required:
        - id
      properties:
        id:
          type: string
          x-stoplight:
            id: 2e38hjk4zd58m
          format: uuid
      additionalProperties: false
    AddOnRateType:
      title: AddOnRateType
      x-stoplight:
        id: 1c3m0qj0ofdao
      enum:
        - RateForEach
        - RatePercentOfTotal
        - PerLoad
        - FuelSurcharge
      example: RateForEach
      default: RateForEach
    Load-Read-Nested:
      title: Load-Read-Nested
      x-stoplight:
        id: zpc98ohudvz2m
      allOf:
        - $ref: '#/components/schemas/Identifier'
        - type: object
          x-stoplight:
            id: 4rcl2v4mcwxe5
          required:
            - quantity
            - unit_of_measure
            - load_id
            - ordinality
          properties:
            quantity:
              type: string
              x-stoplight:
                id: 3crm24cakhqhf
              nullable: true
            unit_of_measure:
              $ref: '#/components/schemas/NullableOrderUnitOfMeasure'
            load_id:
              type: string
              x-stoplight:
                id: xwweeqwdfh9pg
            ordinality:
              type: integer
              x-stoplight:
                id: 4xdv8c9e9p4o8
            ticket:
              $ref: '#/components/schemas/Ticket-Read-Nested'
    InvoiceLineItemType:
      title: InvoiceLineItemType
      x-stoplight:
        id: clkyxnscmds4j
      enum:
        - InvoiceLineItem
        - MaterialRateLineItem
        - FreightRateLineItem
      default: InvoiceLineItem
    NullableOrderUnitOfMeasure:
      title: NullableOrderUnitOfMeasure
      x-stoplight:
        id: rtlna368z495u
      allOf:
        - $ref: '#/components/schemas/OrderUnitOfMeasure'
      type: string
      nullable: true
    Error-Response:
      title: Error-Response
      x-stoplight:
        id: 52cydhphee3qe
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/Error'
      additionalProperties: false
    UnauthenticatedError-Response:
      title: UnauthenticatedError-Response
      x-stoplight:
        id: o477eph7ttbzt
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/UnauthenticatedError'
      additionalProperties: false
    ModelError-Response:
      title: ModelError-Response
      x-stoplight:
        id: payf9ndh3l6np
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/ModelError'
      additionalProperties: false
    Ticket-Read-Nested:
      title: Ticket-Read-Nested
      x-stoplight:
        id: sxhhxkcgkj6ep
      allOf:
        - $ref: '#/components/schemas/Identifier'
        - type: object
          x-stoplight:
            id: u7esfoogq8q49
          required:
            - ticket_number
            - preview_url
          properties:
            ticket_number:
              type: string
              x-stoplight:
                id: kzx5yw8vvwbra
              nullable: true
            preview_url:
              type: string
              x-stoplight:
                id: h1do11irp24bw
              format: uri
              nullable: true
    OrderUnitOfMeasure:
      title: OrderUnitOfMeasure
      x-stoplight:
        id: kahcgn7w8swdv
      enum:
        - Load
        - Tonne
        - Ton
        - Yard
        - Meter
        - Foot
        - Liter
        - Hour
        - Bushel
        - Gallon
        - CubicMeter
        - Mile
        - Kilometer
        - Barrel
        - Bag
        - Pallet
      example: Load
    Error:
      title: Error
      x-stoplight:
        id: 3g57kkik3l464
      type: object
      description: An Error.
      required:
        - code
      properties:
        code:
          type: string
          x-stoplight:
            id: 7o9x1t8v0bgfo
      additionalProperties: false
    UnauthenticatedError:
      title: UnauthenticatedError
      x-stoplight:
        id: 202o69l0fs40h
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          x-stoplight:
            id: tg10dt7s0l6bw
          properties:
            error_type:
              type: string
              x-stoplight:
                id: wvq8c0qsym4hz
          required:
            - error_type
    ModelError:
      title: ModelError
      x-stoplight:
        id: nhp6714o4j1qt
      description: A Model-specific error
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          required:
            - errors
          properties:
            errors:
              type: array
              x-stoplight:
                id: m4ul9vcq2deh6
              items:
                $ref: '#/components/schemas/ModelError-Item'
    ModelError-Item:
      title: ModelError-Item
      x-stoplight:
        id: b93chwval2t8d
      type: object
      required:
        - model
        - field
        - message
      properties:
        model:
          type: string
          x-stoplight:
            id: 30myfyjkno8ao
          description: The Model associated with this Error
        field:
          type: string
          x-stoplight:
            id: 8gl4ed3uxhdws
          description: The field associated with this Error
        message:
          type: string
          x-stoplight:
            id: bmgbrtmw17qsj
          description: The Error message
      additionalProperties: false
  responses:
    Error:
      description: Error response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error-Response'
            type: object
    UnauthenticatedError:
      description: Example response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UnauthenticatedError-Response'
            type: object
    ModelError:
      description: ''
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ModelError-Response'
            type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````