---
id: upload-file
title: "Upload File"
description: "Uploads a CSV or JSON file and saves its data to MongoDB."
sidebar_label: "Upload File"
hide_title: true
hide_table_of_contents: true
api: eJztVlFzGjcQ/isaPbUzBFxPn3gqdpJJ2ib2BJIX28OIuwWU6CRV2mNKmfvv2ZXu4DA27uQ5vCCk3W93v/20YidRraIc38kZRIyAUT4MZAmxCNqjdlaO5WdvnCqjUOJ6+kW4IP6c3nwUS21AKFuKqDYQhcYoSoVKoBMfnF2511fDe3tvJ2EVx/e2Thhz3HoQY/FG4xoCAX6NzjJiETcJkFwEfRL2LznuW1r/OhazNZyGp1gZuPXDXMPcqor8b1IBypA3hRNp0y3TujUUeil8cBtdQpmy/QRYB8sJM1ypC8yRA8TaYOedY7JnATEO5UA6D0FxtPclEdYWyynSWYB/agp35cqtHO9k4SyCRV5WhKm9CjhaulC9Yvp4OxZrqNKKIhAwaoj8q8ch/8zfMmLQdkVxUKOBfbvEjI+bgUxZPGHOIRWlIRfaqrDtATDj7NlnkxGU3d4sSSqPsZrBfsfWxsjm4YDVqkp8ZAzCVN7PdXku/Yn3glhsOIFs4hZfocCWSR2gZLmmsnqBmN55n/iGEQ4eGGpIG9E7GzOhlxcX/HWs9mldcFeXtRGfWmMK3esalWB0kbo9Yv2ea9n5UrnMgezofc6qo64IoBDKucJz1tfZSkzwRQopuTb6Efij7k0Bp7ryBvZsNIna3y8vT8n7oowuEzXiTQgu/DhzJaDSJnGIUMVTA+OKo9P/oU5NmawgkEAPzKgQVF/8f7ucIDNexdU5qj+QTNQqX5UX7mQio72SL3SF68qhW7tePw70ZnafL+N1pu+pYJ3Ju9ns9gQw97YCXDueZN5FdvEK1/Rr1E6EOMoXjU4ihA2EmHivA/VLrhF9HI9GhXF1OSR+LKqh0iPltXz8skzSqbhm0zQ2IhR10LhNeJPb93/B9h2okno2vnvoG0xZNlkIx2b7HlA82u4UTrFqqino/3J3ByQGTjZ7cc3aLl1y7+ZQzu1KFd/AcqlcZ077Yvjb8OK5YloHQWm16ldFUn+XRzKjo2O69kTRCV0Ilj4NYFX9cTjgLLkhlbI9vHbcv82PzVFKvcfm5yP+8iPeCgfhXxx5o3SaAalLu/YG3HVvYuT+5TtAolzzLaHD3W6hInwOpml4m579wEqm5UYFrRasqzuePetO0zv5jTRKUzv36VWaEGxuak7lqT8IPM+y04QeKo8985P5yjdmf5dvb6YzMl60/0MqV7IPAyfcwWHJSTbNd4hEcq4=
sidebar_class_name: "post api-method"
info_path: reference/api/agenta-backend
custom_edit_url: null
---

import ApiTabs from "@theme/ApiTabs";
import DiscriminatorTabs from "@theme/DiscriminatorTabs";
import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";
import SecuritySchemes from "@theme/ApiExplorer/SecuritySchemes";
import MimeTabs from "@theme/MimeTabs";
import ParamsItem from "@theme/ParamsItem";
import ResponseSamples from "@theme/ResponseSamples";
import SchemaItem from "@theme/SchemaItem";
import SchemaTabs from "@theme/SchemaTabs";
import Markdown from "@theme/Markdown";
import Heading from "@theme/Heading";
import OperationTabs from "@theme/OperationTabs";
import TabItem from "@theme/TabItem";

<Heading
  as={"h1"}
  className={"openapi__heading"}
  children={"Upload File"}
>
</Heading>

<MethodEndpoint
  method={"post"}
  path={"/testsets/upload"}
>
  
</MethodEndpoint>



Uploads a CSV or JSON file and saves its data to MongoDB.

Args:
upload_type : Either a json or csv file.
    file (UploadFile): The CSV or JSON file to upload.
    testset_name (Optional): the name of the testset if provided.

Returns:
    dict: The result of the upload process.

<Heading
  id={"request"}
  as={"h2"}
  className={"openapi-tabs__heading"}
  children={"Request"}
>
</Heading>

<MimeTabs
  className={"openapi-tabs__mime"}
>
  <TabItem
    label={"multipart/form-data"}
    value={"multipart/form-data-schema"}
  >
    <details
      style={{}}
      className={"openapi-markdown__details mime"}
      data-collapsed={false}
      open={true}
    >
      <summary
        style={{}}
        className={"openapi-markdown__details-summary-mime"}
      >
        <h3
          className={"openapi-markdown__details-summary-header-body"}
        >
          Body
        </h3><strong
          className={"openapi-schema__required"}
        >
          required
        </strong>
      </summary><div
        style={{"textAlign":"left","marginLeft":"1rem"}}
      >
        
      </div><ul
        style={{"marginLeft":"1rem"}}
      >
        <SchemaItem
          collapsible={false}
          name={"upload_type"}
          required={false}
          schemaName={"Upload Type (string)"}
          qualifierMessage={undefined}
          schema={{"type":"string","title":"Upload Type"}}
        >
          
        </SchemaItem><SchemaItem
          collapsible={false}
          name={"file"}
          required={true}
          schemaName={"binary"}
          qualifierMessage={undefined}
          schema={{"type":"string","format":"binary","title":"File"}}
        >
          
        </SchemaItem><SchemaItem
          collapsible={true}
          className={"schemaItem"}
        >
          <details
            style={{}}
            className={"openapi-markdown__details"}
          >
            <summary
              style={{}}
            >
              <strong>
                testset_name
              </strong><span
                style={{"opacity":"0.6"}}
              >
                 object
              </span>
            </summary><div
              style={{"marginLeft":"1rem"}}
            >
              
            </div><div>
              <span
                className={"badge badge--info"}
              >
                anyOf
              </span><SchemaTabs>
                <TabItem
                  label={"MOD1"}
                  value={"0-item-properties"}
                >
                  <div
                    style={{"marginTop":".5rem","marginBottom":".5rem"}}
                  >
                    
                    
                    string
                    
                    
                  </div>
                </TabItem>
              </SchemaTabs>
            </div>
          </details>
        </SchemaItem><SchemaItem
          collapsible={false}
          name={"app_id"}
          required={false}
          schemaName={"App Id (string)"}
          qualifierMessage={undefined}
          schema={{"type":"string","title":"App Id"}}
        >
          
        </SchemaItem>
      </ul>
    </details>
  </TabItem>
</MimeTabs><div>
  <div>
    <ApiTabs
      label={undefined}
      id={undefined}
    >
      <TabItem
        label={"200"}
        value={"200"}
      >
        <div>
          
          
          Successful Response
          
          
        </div><div>
          <MimeTabs
            className={"openapi-tabs__mime"}
            schemaType={"response"}
          >
            <TabItem
              label={"application/json"}
              value={"application/json"}
            >
              <SchemaTabs
                className={"openapi-tabs__schema"}
              >
                <TabItem
                  label={"Schema"}
                  value={"Schema"}
                >
                  <details
                    style={{}}
                    className={"openapi-markdown__details response"}
                    data-collapsed={false}
                    open={true}
                  >
                    <summary
                      style={{}}
                      className={"openapi-markdown__details-summary-response"}
                    >
                      <strong>
                        Schema
                      </strong>
                    </summary><div
                      style={{"textAlign":"left","marginLeft":"1rem"}}
                    >
                      
                    </div><ul
                      style={{"marginLeft":"1rem"}}
                    >
                      <SchemaItem
                        collapsible={false}
                        name={"id"}
                        required={true}
                        schemaName={"Id (string)"}
                        qualifierMessage={undefined}
                        schema={{"type":"string","title":"Id"}}
                      >
                        
                      </SchemaItem><SchemaItem
                        collapsible={false}
                        name={"name"}
                        required={true}
                        schemaName={"Name (string)"}
                        qualifierMessage={undefined}
                        schema={{"type":"string","title":"Name"}}
                      >
                        
                      </SchemaItem><SchemaItem
                        collapsible={false}
                        name={"created_at"}
                        required={true}
                        schemaName={"Created At (string)"}
                        qualifierMessage={undefined}
                        schema={{"type":"string","title":"Created At"}}
                      >
                        
                      </SchemaItem>
                    </ul>
                  </details>
                </TabItem><TabItem
                  label={"Example (from schema)"}
                  value={"Example (from schema)"}
                >
                  <ResponseSamples
                    responseExample={"{\n  \"id\": \"string\",\n  \"name\": \"string\",\n  \"created_at\": \"string\"\n}"}
                    language={"json"}
                  >
                    
                  </ResponseSamples>
                </TabItem>
              </SchemaTabs>
            </TabItem>
          </MimeTabs>
        </div>
      </TabItem><TabItem
        label={"422"}
        value={"422"}
      >
        <div>
          
          
          Validation Error
          
          
        </div><div>
          <MimeTabs
            className={"openapi-tabs__mime"}
            schemaType={"response"}
          >
            <TabItem
              label={"application/json"}
              value={"application/json"}
            >
              <SchemaTabs
                className={"openapi-tabs__schema"}
              >
                <TabItem
                  label={"Schema"}
                  value={"Schema"}
                >
                  <details
                    style={{}}
                    className={"openapi-markdown__details response"}
                    data-collapsed={false}
                    open={true}
                  >
                    <summary
                      style={{}}
                      className={"openapi-markdown__details-summary-response"}
                    >
                      <strong>
                        Schema
                      </strong>
                    </summary><div
                      style={{"textAlign":"left","marginLeft":"1rem"}}
                    >
                      
                    </div><ul
                      style={{"marginLeft":"1rem"}}
                    >
                      <SchemaItem
                        collapsible={true}
                        className={"schemaItem"}
                      >
                        <details
                          style={{}}
                          className={"openapi-markdown__details"}
                        >
                          <summary
                            style={{}}
                          >
                            <span
                              className={"openapi-schema__container"}
                            >
                              <strong
                                className={"openapi-schema__property"}
                              >
                                detail
                              </strong><span
                                className={"openapi-schema__name"}
                              >
                                 object[]
                              </span>
                            </span>
                          </summary><div
                            style={{"marginLeft":"1rem"}}
                          >
                            <li>
                              <div
                                style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}
                              >
                                Array [
                              </div>
                            </li><SchemaItem
                              collapsible={true}
                              className={"schemaItem"}
                            >
                              <details
                                style={{}}
                                className={"openapi-markdown__details"}
                              >
                                <summary
                                  style={{}}
                                >
                                  <span
                                    className={"openapi-schema__container"}
                                  >
                                    <strong
                                      className={"openapi-schema__property"}
                                    >
                                      loc
                                    </strong><span
                                      className={"openapi-schema__name"}
                                    >
                                       object[]
                                    </span><span
                                      className={"openapi-schema__divider"}
                                    >
                                      
                                    </span><span
                                      className={"openapi-schema__required"}
                                    >
                                      required
                                    </span>
                                  </span>
                                </summary><div
                                  style={{"marginLeft":"1rem"}}
                                >
                                  <li>
                                    <div
                                      style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem","paddingBottom":".5rem"}}
                                    >
                                      Array [
                                    </div>
                                  </li><div>
                                    <span
                                      className={"badge badge--info"}
                                    >
                                      anyOf
                                    </span><SchemaTabs>
                                      <TabItem
                                        label={"MOD1"}
                                        value={"0-item-properties"}
                                      >
                                        <div
                                          style={{"marginTop":".5rem","marginBottom":".5rem"}}
                                        >
                                          
                                          
                                          string
                                          
                                          
                                        </div>
                                      </TabItem><TabItem
                                        label={"MOD2"}
                                        value={"1-item-properties"}
                                      >
                                        <div
                                          style={{"marginTop":".5rem","marginBottom":".5rem"}}
                                        >
                                          
                                          
                                          integer
                                          
                                          
                                        </div>
                                      </TabItem>
                                    </SchemaTabs>
                                  </div><li>
                                    <div
                                      style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}
                                    >
                                      ]
                                    </div>
                                  </li>
                                </div>
                              </details>
                            </SchemaItem><SchemaItem
                              collapsible={false}
                              name={"msg"}
                              required={true}
                              schemaName={"Message (string)"}
                              qualifierMessage={undefined}
                              schema={{"type":"string","title":"Message"}}
                            >
                              
                            </SchemaItem><SchemaItem
                              collapsible={false}
                              name={"type"}
                              required={true}
                              schemaName={"Error Type (string)"}
                              qualifierMessage={undefined}
                              schema={{"type":"string","title":"Error Type"}}
                            >
                              
                            </SchemaItem><li>
                              <div
                                style={{"fontSize":"var(--ifm-code-font-size)","opacity":"0.6","marginLeft":"-.5rem"}}
                              >
                                ]
                              </div>
                            </li>
                          </div>
                        </details>
                      </SchemaItem>
                    </ul>
                  </details>
                </TabItem><TabItem
                  label={"Example (from schema)"}
                  value={"Example (from schema)"}
                >
                  <ResponseSamples
                    responseExample={"{\n  \"detail\": [\n    {\n      \"loc\": [\n        \"string\",\n        0\n      ],\n      \"msg\": \"string\",\n      \"type\": \"string\"\n    }\n  ]\n}"}
                    language={"json"}
                  >
                    
                  </ResponseSamples>
                </TabItem>
              </SchemaTabs>
            </TabItem>
          </MimeTabs>
        </div>
      </TabItem>
    </ApiTabs>
  </div>
</div>
      