# Restsharp POST /files/v3/files Bad Request with no Content

**URL:** <https://community.hubspot.com/t/restsharp-post-files-v3-files-bad-request-with-no-content/83755>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [June 20, 2023, 2:36pm UTC](https://community.hubspot.com/t/restsharp-post-files-v3-files-bad-request-with-no-content/83755 "2023-06-20T14:36:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPerna](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@JPerna](https://community.hubspot.com/u/JPerna)\
**Post date:** [June 20, 2023, 2:36pm UTC](https://community.hubspot.com/t/restsharp-post-files-v3-files-bad-request-with-no-content/83755/1 "2023-06-20T14:36:01Z")

</div>

I am trying to upload files through the /files/v3/files endpoint. I am using Restsharp in C#. My code is below.

Method for API call:

Spoiler

public T FileUpload\<T\>(File file)  
{  
var client = new RestClient(“[https://api.hubapi.com/files/v3/files](https://api.hubapi.com/files/v3/files)”);  
var request = new RestRequest(“”, Method.Post);  
request.AlwaysMultipartFormData = true;  
request.AddFile(“file”, file.FileBytes, file.fileName, “application/octet-stream”);  
request.AddHeader(“authorization”, $“Bearer {\_Private\_Key}”);  
request.AddHeader(“accept”, “application/json”);  
request.AddHeader(“content-type”, “multipart/form-data”);  
request.AddParameter(“folderId”, file.id);  
request.AddParameter(“options”, file.options);  
var response = client.Execute\<T\>(request);  
if (response.IsSuccessful)  
{  
return response.Data;  
}  
throw new FailedApiCallException(response);  
}

File class:

Spoiler

public class File  
{  
public string id { get; set; }  
public string fileName { get; set; }  
public string options = “{access:‘PRIVATE’}”;  
[JsonIgnore]  
public byte[] FileBytes { get; set; }

public File(IFormFile file)  
{  
byte[] bytes = new byte[file.Length];  
file.OpenReadStream().Read(bytes, 0, (int)file.Length);  
FileBytes = bytes;  
fileName = file.FileName;  
}

}

No matter how I format my request I get back a ‘Bad Request’ Response. Unlike most Bad Request Responses, it never has any content/further info.

 ![JPerna_0-1687272213041.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/1/3/13b98da498d45caa6dbfed11dfdb279eb7e2f5f5.png)

I have tried many different variations of this code, and this is the only endpoint without code examples that Ive seens on the documentation. I have tried many examples from other posts on this forum but none have worked for me. Even a basic Postman example would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [June 21, 2023, 7:46am UTC](https://community.hubspot.com/t/restsharp-post-files-v3-files-bad-request-with-no-content/83755/2 "2023-06-21T07:46:36Z")

</div>

Hello @JPerna  
AddHeader(“content-type”, “multipart/form-data”); header. This header is not necessary for the /files/v3/files endpoint. In fact, if you include this header, you will get a “Bad Request” response. remove the AddHeader(“content-type”, “multipart/form-data”); header from your code. Once you have done this, your request should be successful.

```lia-code-sample
POST https://api.hubapi.com/files/v3/files
Authorization: Bearer your_access_token
Content-Type: application/json

{
 "file": {
 "fileName": "my-file.pdf",
 "fileBytes": "your_file_bytes"
 }
}

```

---

<div class="post-metadata">

**Author:** ![SCohan](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@SCohan](https://community.hubspot.com/u/SCohan)\
**Post date:** [January 14, 2024, 1:46am UTC](https://community.hubspot.com/t/restsharp-post-files-v3-files-bad-request-with-no-content/83755/3 "2024-01-14T01:46:19Z")

</div>

I am starting work on our v3 API integration using Contacts. I’ve tried both sample code on HS dev docs, Endpoints Contacts C# example code, as well as code generated after successful Postman v3 Contacts API call, using restSharp, and then tried C# HTTP Request. I’m on .NET 4.7 Webforms. Visual Studio 2017, the system will not allow synchronous methods. But I’m in a control, .ascx, not at page level so I cannot add Asynchronous=“True” to the page directive. Any advice is appreciated.

---

<div class="post-metadata">

**Author:** ![SCohan](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@SCohan](https://community.hubspot.com/u/SCohan)\
**Post date:** [February 12, 2024, 3:00am UTC](https://community.hubspot.com/t/restsharp-post-files-v3-files-bad-request-with-no-content/83755/4 "2024-02-12T03:00:33Z")

</div>

I’m in the same boat as you. You may have already figured this one out, but yes.

Adding Asynchronous=“True” to your page directive will allow for async, task, await, etc. code.🤗
