# Replace the expense file

> Replaces only the stored file; every other field is kept. Fires the expense.updated webhook.

## POST /expenses/{expense}/file

Replaces only the stored file; every other field is kept. Fires the `expense.updated` webhook.

### Request and responses

```json
{
  "servers": [
    {
      "url": "https://app.fsaskaita.lt/api",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "operation": {
    "operationId": "replaceExpenseFile",
    "description": "Replaces only the stored file; every other field is kept. Fires the `expense.updated` webhook.",
    "summary": "Replace the expense file",
    "tags": [
      "Expenses"
    ],
    "parameters": [
      {
        "name": "expense",
        "in": "path",
        "required": true,
        "description": "The expense ID.",
        "schema": {
          "type": "string"
        }
      }
    ],
    "requestBody": {
      "required": true,
      "content": {
        "multipart/form-data": {
          "schema": {
            "$ref": "#/components/schemas/ExpenseFileInput"
          }
        }
      }
    },
    "responses": {
      "200": {
        "description": "`Expense`",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "data": {
                  "$ref": "#/components/schemas/Expense"
                }
              },
              "required": [
                "data"
              ]
            }
          }
        }
      },
      "401": {
        "$ref": "#/components/responses/AuthenticationException"
      },
      "403": {
        "$ref": "#/components/responses/AuthorizationException"
      },
      "404": {
        "description": "The expense does not exist or belongs to another business.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "message"
              ]
            }
          }
        }
      },
      "422": {
        "$ref": "#/components/responses/ValidationException"
      },
      "429": {
        "description": "Rate limit exceeded. The limit is 60 requests per minute per business, shared across all of its tokens. Wait `Retry-After` seconds before retrying.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "message"
              ]
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait before retrying.",
            "schema": {
              "type": "integer"
            }
          },
          "X-RateLimit-Limit": {
            "description": "Requests allowed per minute.",
            "schema": {
              "type": "integer"
            }
          },
          "X-RateLimit-Remaining": {
            "description": "Requests left in the current minute.",
            "schema": {
              "type": "integer"
            }
          },
          "X-RateLimit-Reset": {
            "description": "Unix timestamp at which the window resets.",
            "schema": {
              "type": "integer"
            }
          }
        }
      }
    }
  },
  "securitySchemes": {
    "bearerAuth": {
      "type": "http",
      "description": "Business token created in the app under Settings, Integrations, API. The token is scoped to exactly one business, has no expiry and is shown only once. Send it as `Authorization: Bearer <token>` together with `Accept: application/json`.",
      "scheme": "bearer"
    }
  }
}
```

### Referenced components

```json
{
  "#/components/schemas/ExpenseFileInput": {
    "type": "object",
    "description": "Multipart body of `POST /expenses/{expense}/file`.",
    "properties": {
      "file": {
        "type": "string",
        "format": "binary",
        "contentMediaType": "application/octet-stream",
        "description": "The new document file: jpeg, jpg, bmp, gif, pdf, png, tiff, xlsx, xls, doc, docx or odf."
      }
    },
    "required": [
      "file"
    ],
    "title": "ExpenseFileInput"
  },
  "#/components/schemas/Expense": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string",
        "format": "uuid"
      },
      "date": {
        "type": [
          "string",
          "null"
        ],
        "format": "date",
        "description": "Document date, `Y-m-d`."
      },
      "total": {
        "type": "number",
        "description": "Amount including VAT."
      },
      "currency": {
        "type": "string"
      },
      "seller": {
        "type": "string"
      },
      "created_at": {
        "type": "integer",
        "description": "Unix timestamp, seconds."
      },
      "updated_at": {
        "type": "integer",
        "description": "Unix timestamp, seconds."
      }
    },
    "required": [
      "id",
      "date",
      "total",
      "currency",
      "seller",
      "created_at",
      "updated_at"
    ],
    "title": "Expense"
  },
  "#/components/responses/AuthenticationException": {
    "description": "Unauthenticated",
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "message": {
              "type": "string",
              "description": "Error overview."
            }
          },
          "required": [
            "message"
          ]
        }
      }
    }
  },
  "#/components/responses/AuthorizationException": {
    "description": "Authorization error",
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "message": {
              "type": "string",
              "description": "Error overview."
            }
          },
          "required": [
            "message"
          ]
        }
      }
    }
  },
  "#/components/responses/ValidationException": {
    "description": "Validation error",
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "message": {
              "type": "string",
              "description": "Errors overview."
            },
            "errors": {
              "type": "object",
              "description": "A detailed description of each field that failed validation.",
              "additionalProperties": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "required": [
            "message",
            "errors"
          ]
        }
      }
    }
  }
}
```
