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

# Upsert

> Insert or update metadata for files and tags.

## Request Body

| Field                 | Type                  | Description                                                                  |
|-----------------------|-----------------------|------------------------------------------------------------------------------|
| `data_connector_name` | `Optional[str]`       | Name of the data connector (vector database profile).                        |
| `dataslice_id`        | `Optional[str]`       | ID of the dataslice to upsert metadata for.                                  |
| `metadata`            | `Deasy_Metadata`      | Metadata to upsert in the form `{file_name: {tag_name: tag_value}}`.         |

## Response

- **200**: Metadata upserted successfully  
    - Returns: `{ "success": bool }`
- **500**: Internal Server Error

## Example

```json
{
  "data_connector_name": "my-connector",
  "metadata": {
    "document1.pdf": {
      "category": "invoice",
      "date": "2024-01-15"
    },
    "document2.pdf": {
      "category": "receipt",
      "status": "processed"
    }
  }
}
```



## OpenAPI

````yaml /deasy-openapi-stainless.yml post /metadata/upsert
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: /rest/unstructured
security: []
paths:
  /metadata/upsert:
    post:
      tags:
        - Metadata
      summary: Upsert
      description: >-
        Insert or update metadata for files and tags.


        ## Request Body


        | Field                 | Type                  |
        Description                                                                 
        |

        |-----------------------|-----------------------|------------------------------------------------------------------------------|

        | `data_connector_name` | `Optional[str]`       | Name of the data
        connector (vector database profile).                        |

        | `dataslice_id`        | `Optional[str]`       | ID of the dataslice to
        upsert metadata for.                                  |

        | `metadata`            | `Deasy_Metadata`      | Metadata to upsert in
        the form `{file_name: {tag_name: tag_value}}`.         |


        ## Response


        - **200**: Metadata upserted successfully  
            - Returns: `{ "success": bool }`
        - **500**: Internal Server Error


        ## Example


        ```json

        {
          "data_connector_name": "my-connector",
          "metadata": {
            "document1.pdf": {
              "category": "invoice",
              "date": "2024-01-15"
            },
            "document2.pdf": {
              "category": "receipt",
              "status": "processed"
            }
          }
        }

        ```
      operationId: upsert_metadata_route_metadata_upsert_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertMetadataRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpsertMetadataResponse'
        '403':
          description: Missing token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: Too many requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
        '500':
          description: >-
            Internal Server Error. An unexpected error occurred while processing
            the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
      security:
        - BasicAuth: []
        - BearerAuth: []
          UserIdAuth: []
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from unstructured import UnstructuredClient

            client = UnstructuredClient(
                username=os.environ.get("UNSTRUCTURED_USERNAME"),  # This is the default and can be omitted
                password=os.environ.get("UNSTRUCTURED_PASSWORD"),  # This is the default and can be omitted
            )
            response = client.metadata.upsert(
                metadata={
                    "foo": {
                        "foo": {}
                    }
                },
            )
            print(response.success)
        - lang: JavaScript
          source: >-
            import UnstructuredClient from 'unstructured-sdk';


            const client = new UnstructuredClient({
              authMethod: 'My Auth Method',
              username: process.env['UNSTRUCTURED_USERNAME'], // This is the default and can be omitted
              password: process.env['UNSTRUCTURED_PASSWORD'], // This is the default and can be omitted
            });


            const response = await client.metadata.upsert({ metadata: { foo: {
            foo: {} } } });


            console.log(response.success);
components:
  schemas:
    UpsertMetadataRequest:
      properties:
        data_connector_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Data Connector Name
        dataslice_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Dataslice Id
        metadata:
          anyOf:
            - additionalProperties:
                additionalProperties:
                  $ref: '#/components/schemas/TagMetadata'
                type: object
              type: object
              title: MetadataByTagAndChunk
            - additionalProperties:
                additionalProperties:
                  $ref: '#/components/schemas/Metadata'
                type: object
              type: object
              title: MetadataByChunk
          title: Metadata
      type: object
      required:
        - metadata
      title: UpsertMetadataRequest
    UpsertMetadataResponse:
      properties:
        success:
          type: boolean
          title: Success
      type: object
      required:
        - success
      title: UpsertMetadataResponse
    HTTPError:
      properties:
        detail:
          type: string
          title: Detail
      type: object
      required:
        - detail
      title: HTTPError
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    TagMetadata:
      properties:
        chunk_level:
          anyOf:
            - additionalProperties:
                anyOf:
                  - $ref: '#/components/schemas/Metadata'
                  - type: 'null'
              type: object
            - type: 'null'
          title: Chunk Level
        file_level:
          anyOf:
            - $ref: '#/components/schemas/Metadata'
            - type: 'null'
      type: object
      title: TagMetadata
    Metadata:
      properties:
        values:
          items:
            anyOf:
              - type: string
              - type: number
              - type: integer
          type: array
          title: Values
        evidence:
          anyOf:
            - type: string
            - type: 'null'
          title: Evidence
      type: object
      required:
        - values
      title: Metadata
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
    BearerAuth:
      type: http
      scheme: bearer
    UserIdAuth:
      type: apiKey
      in: header
      name: X-User-ID

````