Can you provide a C# example to upload an attachment to a contact object.

Empty

Hi, @aadiver, This specific endpoint cannot be tested from the documentation page. This is why HubSpot doesn’t provide an example. Please see this post for one example — Is there an example of how to access the import API endpoint using c# and .net

We’ll see if the community has any additional insights.

Best,

Jaycee

The link you provided is for importing a csv file with objetcs (contact, company) into Hubspot.

I’m looking for code to upload an attachment (a resume of a candidate) and attach this to a contact.

I’ve already the following working code, but it is for the legacy api. And it is only the part of uploading the attachment. But I’m missing the piece to assoicate it with a contact.

I’m looking also to use the new api.

public async Task UploadCViaRestClient()
{
var file = File.ReadAllBytes(@“<PATH TO CV>”);
var client = new RestClient(“https://api.hubapi.com/”);
var request = new RestRequest(“/filemanager/api/v3/files/upload”, Method.Post);

client.AddDefaultHeader(“Authorization”, string.Format(“Bearer {0}”, TOKEN));

request.AddFile(“file”, file, “CV-of-candidate.pdf”, “application/octet-stream”);

request.AddParameter(“folderPath”, “/CV”);

var fileOptions = new
{
access = @“PUBLIC_NOT_INDEXABLE”,
};
//Tranform it to Json object
string jsonData = JsonConvert.SerializeObject(fileOptions);
request.AddParameter(“options”, jsonData);

var response = client.Execute(request);
}