# Storage bucket requests

> Uploading files to an existing storage bucket using Orchestrator APIs is a two-part process:

## Add a file to a storage bucket

Uploading files to an existing storage bucket using Orchestrator APIs is a two-part process:

* First you need to call the GET `/odata/Buckets({key})/UiPath.Server.Configuration.OData.GetWriteUri` endpoint, that returns an URI and the HTTP method as a response.
* Then you need to use the HTTP method from the GET response to call the `{URI}` endpoint, attach the file you want to upload in binary format, and send it to the URI obtained from the GET request.

## GET endpoint

GET `https://{yourDomain}/{organizationName}/{tenantName}/orchestrator_/odata/Buckets({key})/UiPath.Server.Configuration.OData.GetWriteUri`

To find out the URI and the HTTP verb, you need to upload the file to an existing storage bucket, then make a GET request to `/odata/Buckets({key})/UiPath.Server.Configuration.OData.GetWriteUri`.

Provide the following parameters and headers:

### Path parameters

| Path param | Data type | Description |
| --- | --- | --- |
| `key`  (required) | String | The ID of the storage bucket where you want to upload your file. |

### Query parameters

| Param | Data type | Description |
| --- | --- | --- |
| `path`  (required) | String | The name of the file you want to upload, together with its extension.  For example, "my_file.txt". |
| `contentType`  (required) | String | The content type for the file extension.  For example, the content type of `.txt` extensions is `text/plain`. |

### Request headers

```
--header 'Authorization: Bearer {access_token}'\
--header 'Content-Type: application/json' \
--header 'X-UIPATH-OrganizationUnitId: {the_ID_of_the_folder_that_contains_the_storage_bucket}' \
```

The `X-UIPATH-OrganizationUnitId` is the ID of the folder that contains the storage bucket.

### Example request

```
curl --location --request GET 'https://{yourDomain}/{organizationName}/{tenantName}/orchestrator_/odata/Buckets(28053)/UiPath.Server.Configuration.OData.GetWriteUri?path=my_file.txt&contentType=text/plain' \
--header 'x-uipath-organizationunitid: 3991326' \
--header 'Authorization: Bearer 1234'
```

The access token in the example is `1234` for length considerations.

### Response body

The response body contains the URI and the HTTP verb required to upload the file to the storage bucket in binary format.

```
{
    "@odata.context": "https://{yourDomain}/{organizationName}/{tenantName}/orchestrator_/odata/$metadata#UiPath.Server.Configuration.OData.BlobFileAccessDto",
    "Uri": "https://cr.blob.core.windows.net/orchestrator-4871-905f/BlobFilePersistence/2760e0fe-0fa7/my_file.txt?sv=2021-08-06&st=2023-01-13T16%3A32%3A12Z&se=2023-01-13T17%3A32%3A42Z&sr=b&sp=cw&sig=xB3W02xGYHfw%3D",
    "Verb": "PUT",
    "Headers": {
        "Keys": [
            "x-ms-blob-type"
        ],
        "Values": [
            "BlockBlob"
        ]
    }
}
```

## PUT endpoint

PUT `{URI}`

The URI is the value of the "Uri" key from the response body.

### Request headers

```
--header 'x-ms-blob-type: BlockBlob' \
--header 'Content-Type: text/plain'
```

:::note
* Make sure to include the headers you receive in the GET response body, and assign values to them. For example, for Azure Blob
Storage, the returned header is `x-ms-blob-type-header`, which uses the `BlockBlob` value.
* Do not use an authorization header with this request.
:::

### Request body

Upload the file in binary format. You must use the same file you used as a query parameter in the GET request. In this case, "my_file.txt".

```
--data-binary '@/C:/Users/adam.eve/OneDrive/Documents/my_file.txt'
```

### Example request

Let's say you gathered all the information needed to build the API call.

```
curl --location --request PUT 'https://cr.blob.core.windows.net/orchestrator-4871-905f/BlobFilePersistence/2760e0fe-0fa7/my_file.txt?sv=2021-08-06&st=2023-01-13T16%3A32%3A12Z&se=2023-01-13T17%3A32%3A42Z&sr=b&sp=cw&sig=xB3W02xGYHfw%3D' \
--header 'x-ms-blob-type: BlockBlob' \
--header 'Content-Type: text/plain' \
--data-binary '@/C:/Users/adam.eve/OneDrive/Documents/my_file.txt'
```

In the Orchestrator UI, the file is visible in your storage bucket.
