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

# Update maintenance record

> Partially update a maintenance record by ID: change only the fields you send, such as status, cost, vendor or reminders, with If-Match concurrency.

The Update Maintenance Record endpoint applies a partial update to an existing maintenance record. Send only the fields you want to change. A field left out of the body keeps its saved value, and an empty string clears a free-text field. For more information on how versioning works and how to include it in your requests, please refer to the [Versioning](https://docs.alvys.com/en/api/guides/versioning.md) page.

> [!NOTE]
>
> This endpoint requires the `maintenance:update` scope. See [Authentication](https://docs.alvys.com/en/api/guides/authentication-1.md).

### If-Match is required

This endpoint uses optimistic concurrency. Send the record's current `ETag` in the `If-Match` header. The `ETag` response header of [Get maintenance record](https://docs.alvys.com/en/api/reference/maintenance/get-maintenance-record.md), of [Create maintenance record](https://docs.alvys.com/en/api/reference/maintenance/create-maintenance-record.md), and of every successful update carries it.

* If you omit `If-Match`, the request is rejected with `428 Precondition Required`.
* If the record changed after you read it, the request is rejected with `412 Precondition Failed`. Get the record again and retry with the new `ETag`.

### Clearing values

* **Free-text fields** (`Description`, `Comments`, `PO`, `Reference`, `WorkPerformed`): send an empty string.
* **RepairShop and Vendor:** send an empty object, `{}`.
* **Category** cannot be cleared. Sending an empty object is rejected with `400 Bad Request`.
* **Reminders** are replaced as a whole list: send the full list you want to keep, or `[]` to remove all of them.

> [!WARNING]
>
> If your JSON serializer writes an unset list as `[]`, it clears the record's reminders. Leave `Reminders` out of the body when you do not mean to change them.

`Category`, `RepairShop` and `Vendor` are resolved by `Name`, as in [Create maintenance record](https://docs.alvys.com/en/api/reference/maintenance/create-maintenance-record.md#category-repair-shop-and-vendor).

### The asset cannot be changed

A maintenance record stays on the truck or trailer it was created for. The body has no `Asset` field. To move work to another asset, create a new record against it.

### Records linked to a driver deduction

When `IsDeducted` is `true`, the record is linked to a driver settlement deduction made in Alvys. `Category`, `Description`, `Amount` and `Date` cannot be changed through this endpoint, because the change would replace that deduction and change the driver's pay. A request that sends any of them is rejected with `422 Unprocessable Entity` and the problem `type` `https://api.alvys.com/errors/UnprocessableEntity/MaintenanceDeductionLocked`. You can still change the other fields, or edit the record in Alvys.

### A body with nothing to change

A body with no fields, `{}`, changes nothing. The request still needs a current `If-Match`, and it returns `200 OK` with the record and its unchanged `ETag`.

***

### Request parameters

The following parameters are required in the URL path:

| Parameter | Type | Required | Description |
| - | - | - | - |
| version | String | Yes | The version of the API. |
| id | String | Yes | The unique identifier of the maintenance record. |

The following header is required:

| Header | Required | Description |
| - | - | - |
| If-Match | Yes | The current `ETag` of the maintenance record. |

***

### Request body

All fields are optional. Limits and allowed values are the same as in [Create maintenance record](https://docs.alvys.com/en/api/reference/maintenance/create-maintenance-record.md#request-body).

| Field | Type | Description |
| - | - | - |
| Category | Object | The kind of work, with `Name` and an optional `Id`. Cannot be cleared. |
| Status | String | One of `Urgent`, `Open`, `Closed` (case-insensitive). |
| Date | String (Date-Time) | When the work was done or is scheduled. |
| Description | String | A short summary of the work. Up to 500 characters. |
| Comments | String | Free-form notes. Up to 2,000 characters. |
| Amount | Number | The total cost in USD. Cannot be negative. |
| PO | String | The purchase order number. Up to 100 characters. |
| Reference | String | Your reference number. Up to 100 characters. |
| RepairShop | Object | Where the work is done, with `Name` and an optional `Id`. Send `{}` to clear it. |
| Vendor | Object | Who bills for the work, with `Name` and an optional `Id`. Send `{}` to clear it. |
| OdometerReading | Number | The odometer of the asset at the time of service, in miles. Cannot be negative. |
| WorkPerformed | String | A longer description of the work done. Up to 2,000 characters. |
| Reminders | Array | Replaces the whole reminder list. Up to 25, each with a `DueDate`. Send `[]` to remove all reminders. |

`ExternalId` cannot be changed.

***

### Example cURL request

```bash theme={null}
curl --location --request PATCH 'https://integrations.alvys.com/api/p/v1/maintenance/4b0e6a52-0000-0000-0000-000000000417' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--header 'If-Match: "00000000-0000-0000-0000-000000000001"' \
--data-raw '{
  "Status": "Closed",
  "Amount": 468.10,
  "Comments": "Final invoice received"
}'
```

Replace `YOUR_ACCESS_TOKEN` with your actual Bearer token and the `If-Match` value with the record's current `ETag`.

***

### Response fields

A successful request returns `200 OK` with the updated record, in the same shape as [Create maintenance record](https://docs.alvys.com/en/api/reference/maintenance/create-maintenance-record.md#response-fields). The new `ETag` is in the `ETag` response header.

***

### Status codes

| Status | Meaning |
| - | - |
| 200 | The record was updated, or the body had nothing to change. |
| 400 | The request body failed validation. The response lists the invalid fields. |
| 401 | The request was not authenticated. |
| 403 | The caller lacks the `maintenance:update` scope. |
| 404 | No maintenance record with this `id` exists, it was deleted, or its asset is outside the subsidiaries your credential can access. |
| 409 | The update clashed with another change saved at the same moment. Get the record again and retry. |
| 412 | The `If-Match` value did not match the current record. Get the record again and retry. |
| 422 | The record is linked to a driver deduction and the body changes `Category`, `Description`, `Amount` or `Date` (`MaintenanceDeductionLocked`). |
| 428 | The `If-Match` header is missing. |
| 429 | The rate limit was exceeded. |

***

### Rate limits

All endpoints are subject to rate limits to protect the API from traffic spikes. For detailed information on rate limits, please refer to the [Rate Limits](https://docs.alvys.com/en/api/guides/rate-limits.md) section.

This page is interactive, allowing you to try a request by specifying the **API version** and the maintenance record **id** in the URL path. As you fill out the parameters, the cURL command on the right side of the page will be automatically updated.


## OpenAPI

````yaml PATCH /api/p/v{version}/maintenance/{id}
openapi: 3.0.1
info:
  title: Alvys
  description: >-
    Alvys provides a robust set of REST APIs to allow you to integrate Alvys
    into virtually any platform. These APIs cover most of Alvys' major product
    areas with additional endpoints being added regularly based on customer
    requests.
  contact:
    name: Alvys Support
    url: https://www.alvys.com/resources/contact/
  version: v1
servers:
  - url: https://integrations.alvys.com
    description: Public API Server
  - url: https://api.alvys.com/
    description: Public API Server
security:
  - Public: []
tags:
  - name: Authentication
    description: Obtain an OAuth 2.0 access token for the Alvys Public API.
  - name: Carrier Settlement Statements
    description: >-
      Search carrier settlement statements and retrieve a single statement by
      number.
  - name: Carriers
    description: Read carrier records, search carriers, and manage carrier documents.
  - name: Customers
    description: Create, read, update, delete, and search customer records.
  - name: Deductions
    description: >-
      Create one-time deductions and search or delete existing deduction
      records.
  - name: DispatchPreferences
    description: Dispatch preferences endpoints for reading dispatch rules and preferences.
  - name: Driver Settlement Statements
    description: >-
      Search driver settlement statements and retrieve a single statement by
      number.
  - name: Drivers
    description: >-
      Read driver records, search drivers and driver events, and manage driver
      documents.
  - name: Fuel
    description: Read and search fuel transactions.
  - name: Invoices
    description: >-
      Read invoices, create carrier invoices, and record carrier and customer
      payments.
  - name: Loads
    description: >-
      Read, update, and search loads; manage load documents, notes, and custom
      references.
  - name: Locations
    description: Read and search company location details.
  - name: Maintenance
    description: Read and search maintenance records.
  - name: References
    description: >-
      List tenant custom reference definitions and create or update values on
      existing loads, stops, and trips.
  - name: Subsidiaries
    description: >-
      List your company's subsidiaries and read a single subsidiary, so an
      integration can resolve a subsidiary id to a recognizable name.
  - name: Tenders
    description: Create, accept, reject, cancel, update, and search inbound EDI tenders.
  - name: Tolls
    description: Read and search toll transactions.
  - name: Tracking
    description: >-
      Record an asset's current location or telemetry from a third-party source,
      such as an external ELD or a self-reporting vehicle.
  - name: Trailers
    description: Read trailers, search trailer events, and manage trailer documents.
  - name: Trips
    description: >-
      Read and search trips; manage trip documents, stop appointments, arrivals,
      departures, and stop and trip custom references.
  - name: Trucks
    description: Read trucks, search truck events, and manage truck documents.
  - name: Users
    description: List and search users.
  - name: Visibility
    description: >-
      Read inbound and outbound visibility history and search outbound
      visibility errors.
  - name: Webhooks
    description: >-
      Create, read, update, delete, enable, disable, verify, test, and rotate
      secrets for webhook subscriptions; read event types, delivery logs, and
      health metrics.
  - name: Accessorials
  - name: Credits
paths:
  /api/p/v{version}/maintenance/{id}:
    patch:
      tags:
        - Maintenance
      summary: Update maintenance record
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
        - name: version
          in: path
          description: API version (e.g., 1.0)
          required: true
          schema:
            type: string
            default: '1.0'
            example: '1.0'
        - name: If-Match
          in: header
          required: true
          description: >-
            The maintenance record's current ETag (the ETag response header of
            your most recent GET, POST or PATCH), for optimistic concurrency.
            Required; if omitted the request is rejected with 428.
          schema:
            type: string
      requestBody:
        content:
          application/json-patch+json:
            schema:
              allOf:
                - $ref: >-
                    #/components/schemas/Alvys.Models.Maintenance.MaintenanceUpdateRequest
          application/json:
            schema:
              allOf:
                - $ref: >-
                    #/components/schemas/Alvys.Models.Maintenance.MaintenanceUpdateRequest
          text/json:
            schema:
              allOf:
                - $ref: >-
                    #/components/schemas/Alvys.Models.Maintenance.MaintenanceUpdateRequest
          application/*+json:
            schema:
              allOf:
                - $ref: >-
                    #/components/schemas/Alvys.Models.Maintenance.MaintenanceUpdateRequest
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Alvys.Models.Loads.MaintenanceResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Microsoft.AspNetCore.Mvc.ValidationProblemDetails
        '401':
          description: Unauthorized
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
        '403':
          description: Forbidden
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
        '404':
          description: Not Found
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
        '409':
          description: Conflict
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
        '412':
          description: >-
            Precondition Failed (If-Match ETag did not match the current
            maintenance record)
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
        '422':
          description: Unprocessable Content
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
        '428':
          description: Precondition Required (If-Match header missing)
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
        '429':
          description: Too Many Requests
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
            application/json:
              schema:
                $ref: '#/components/schemas/Microsoft.AspNetCore.Mvc.ProblemDetails'
      security:
        - Public: []
components:
  schemas:
    Alvys.Models.Maintenance.MaintenanceUpdateRequest:
      type: object
      properties:
        Category:
          allOf:
            - $ref: >-
                #/components/schemas/Alvys.Models.Maintenance.MaintenanceReferenceRequest
          nullable: true
        Status:
          type: string
          nullable: true
        Date:
          type: string
          format: date-time
          nullable: true
        Description:
          type: string
          nullable: true
        Comments:
          type: string
          nullable: true
        Amount:
          type: number
          format: double
          nullable: true
        PO:
          type: string
          nullable: true
        Reference:
          type: string
          nullable: true
        RepairShop:
          allOf:
            - $ref: >-
                #/components/schemas/Alvys.Models.Maintenance.MaintenanceReferenceRequest
          nullable: true
        Vendor:
          allOf:
            - $ref: >-
                #/components/schemas/Alvys.Models.Maintenance.MaintenanceReferenceRequest
          nullable: true
        OdometerReading:
          type: number
          format: double
          nullable: true
        WorkPerformed:
          type: string
          nullable: true
        Reminders:
          type: array
          items:
            $ref: >-
              #/components/schemas/Alvys.Models.Maintenance.MaintenanceReminderRequest
          description: >-
            Replaces the whole reminder list when supplied. Omit the property to
            leave the stored reminders unchanged; send [] to remove them all.
            Note the consequence: a client that serializes an unset collection
            as [] will clear this record's reminders, so omit the property
            rather than sending an empty array. Same rule as Email and Phone on
            the customer write surface.
          nullable: true
      additionalProperties: false
    Alvys.Models.Loads.MaintenanceResponse:
      required:
        - Amount
        - Category
        - CreatedAt
        - CreatedBy
        - Id
        - RelatedAsset
        - Status
        - OdometerReading
        - IsDeducted
      type: object
      properties:
        Id:
          type: string
        PO:
          type: string
          nullable: true
        Reference:
          type: string
          nullable: true
        RelatedAsset:
          allOf:
            - $ref: '#/components/schemas/Alvys.Models.Loads.MaintenanceResponseAsset'
        Category:
          allOf:
            - $ref: >-
                #/components/schemas/Alvys.Models.Loads.MaintenanceResponseMaintenanceCategory
        Description:
          type: string
          nullable: true
        Comments:
          type: string
          nullable: true
        Amount:
          allOf:
            - $ref: '#/components/schemas/Alvys.Money'
        RepairShop:
          allOf:
            - $ref: '#/components/schemas/Alvys.Models.Loads.MaintenanceResponseShop'
          nullable: true
        Reminders:
          type: array
          items:
            $ref: '#/components/schemas/Alvys.Models.Maintenance.Asset.Reminder'
          nullable: true
        CreatedAt:
          type: string
          format: date-time
        CreatedBy:
          type: string
        ModifiedAt:
          type: string
          format: date-time
          nullable: true
        ModifiedBy:
          type: string
          nullable: true
        RecordNumber:
          type: string
          description: >-
            Per-tenant sequence number, server-assigned and not writable. Unique
            within your tenant, so it is safe to reconcile against: a
            simultaneous create cannot take the same number. NOT guaranteed
            gapless or strictly increasing - a losing race burns a number and a
            deleted record leaves its number behind, so treat it as an
            identifier, not a count.
          nullable: true
        Status:
          type: string
        Date:
          type: string
          format: date-time
          nullable: true
        OdometerReading:
          type: number
          format: double
        WorkPerformed:
          type: string
          nullable: true
        Vendor:
          allOf:
            - $ref: '#/components/schemas/Alvys.Models.Loads.MaintenanceResponseShop'
          nullable: true
        IsDeducted:
          type: boolean
          description: >-
            True when this record is linked to a driver settlement deduction.
            While true, a PATCH that changes Category, Description, Amount or
            Date is refused with 422, because applying it would replace the
            driver's linked deduction. All other fields stay writable.
        ExternalId:
          type: string
          nullable: true
      additionalProperties: false
    Microsoft.AspNetCore.Mvc.ValidationProblemDetails:
      required:
        - Errors
      type: object
      properties:
        Errors:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
        Type:
          type: string
          nullable: true
        Title:
          type: string
          nullable: true
        Status:
          type: integer
          format: int32
          nullable: true
        Detail:
          type: string
          nullable: true
        Instance:
          type: string
          nullable: true
      additionalProperties: {}
    Microsoft.AspNetCore.Mvc.ProblemDetails:
      type: object
      properties:
        Type:
          type: string
          nullable: true
        Title:
          type: string
          nullable: true
        Status:
          type: integer
          format: int32
          nullable: true
        Detail:
          type: string
          nullable: true
        Instance:
          type: string
          nullable: true
      additionalProperties: {}
    Alvys.Models.Maintenance.MaintenanceReferenceRequest:
      type: object
      properties:
        Id:
          type: string
          nullable: true
        Name:
          type: string
          nullable: true
      additionalProperties: false
    Alvys.Models.Maintenance.MaintenanceReminderRequest:
      required:
        - DueDate
      type: object
      properties:
        DueDate:
          type: string
          format: date-time
      additionalProperties: false
    Alvys.Models.Loads.MaintenanceResponseAsset:
      required:
        - AssetId
        - AssetType
      type: object
      properties:
        AssetId:
          type: string
        AssetNumber:
          type: string
          nullable: true
        AssetType:
          type: string
      additionalProperties: false
    Alvys.Models.Loads.MaintenanceResponseMaintenanceCategory:
      required:
        - Id
        - Name
      type: object
      properties:
        Id:
          type: string
        Name:
          type: string
      additionalProperties: false
    Alvys.Money:
      required:
        - Amount
      type: object
      properties:
        Amount:
          type: number
          format: double
        Currency:
          type: integer
          format: int32
          nullable: true
      additionalProperties: false
    Alvys.Models.Loads.MaintenanceResponseShop:
      required:
        - Id
        - Name
      type: object
      properties:
        Id:
          type: string
        Name:
          type: string
      additionalProperties: false
    Alvys.Models.Maintenance.Asset.Reminder:
      type: object
      properties:
        id:
          type: string
          nullable: true
        DueDate:
          type: string
          format: date-time
          nullable: true
      additionalProperties: false
  securitySchemes:
    Public:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        OAuth 2.0 client-credentials access token. Obtain one from
        https://auth.alvys.com/oauth/token (grant_type=client_credentials,
        audience=https://api.alvys.com/public/), then paste it here. The
        playground sends it as `Authorization: Bearer <token>`.

````