Upload CSV API

This API endpoint allows uploading CSV files with specific format validation.

Endpoint

https://$ORG_BASE_URL/upload-csv (POST)

Request Body

The request body should be a multipart form data containing a single file named "file". Only CSV files are accepted.

Content-Type: multipart/form-data

Form Body Example:

"file": (file object)
"start_time": Date
"end_time": Date
"request_id": Optional[String]

Expected CSV Format

The uploaded CSV file should have the following format:

Column NameData TypeDescription
UTCStringTimestamp in UTC format (e.g., 2024-04-18T11:40:27.874Z)
Sensor_1Float | String | BooleanValue A
Sensor_2Float | String | BooleanValue B
Sensor_3Float | String | BooleanValue C

Code snippet

UTC,Sensor_1,Sensor_2,Sensor_3
2024-04-18T11:40:27.874Z,22.54,45,OFF
2024-04-18T11:55:27.874Z,22.54,45,ON

Maximum File Size

The maximum allowed file size is 30 MB. Files exceeding this limit will be rejected.

Response

Success Response:

JSON

{
  "message": "CSV file uploaded successfully."
}

Error Response:

In case of any errors during upload or validation, an error response with a detailed message will be returned. The error code will depend on the specific error:

  • 401 (Unauthorized): Invalid Auth Token
  • 400 (Bad Request): Invalid file format (not CSV), invalid data type in CSV, or other validation errors.
  • 413 (Payload Too Large): File size exceeds the maximum limit.

Example Usage (using curl):

Bash

curl --location https://$ORG_BASE_URL/upload-csv \
--header 'Authorization: Bearer ••••••' \
--form 'file=@"/path/to/file"' \
--form 'start_time="2024-02-02T13:30:00.000Z"' \
--form 'end_time="2024-02-02T13:31:00.000Z"' \
--form 'request_id="slug"'

Replace your_file.csv with the path to your CSV file and $ORG_BASE_URL with the URL given by the Administrator.

Depending on the type of authentication used, additional headers may be necessary for the provided API.