Document Upload

using System.Net.Http.Headers;
using System.Text;


var filePath = @"test.pdf";

var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("https://api-sandbox.yousign.app/v3/");

httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(
  new MediaTypeWithQualityHeaderValue("application/json"));

httpClient.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Bearer", "REPLACE_WITH_YOUR_API_KEY");

using (var multipartFormContent = new MultipartFormDataContent())
{
   //Load the file and set the file's Content-Type header
  var fileStreamContent = new StreamContent(File.OpenRead(filePath));

  fileStreamContent.Headers.Add("Content-Disposition",
        new string(Encoding.UTF8.GetBytes("form-data; name=\"file\"; filename=\"test.pdf\"").
        Select(b => (char)b).ToArray()));

  // You must specify the file Mime Type "application/pdf" otherwise you will receive a bad request from the API
  fileStreamContent.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

  //Add the file

  
  multipartFormContent.Add(fileStreamContent);

  // Add the the nature field
  multipartFormContent.Add(new StringContent("signable_document"), name: "nature");

  //Send POST request
  var response = await httpClient.PostAsync("documents", multipartFormContent);
  
  response.EnsureSuccessStatusCode();

  Console.WriteLine("Status code:" + response.StatusCode);
}
using RestSharp;

// The doc to upload
var filePath = @"./test.pdf";
// Replace with your sandbox API KEY
var apiKey = "YOUR_API_KEY";

// Init the client (for sandbox API)
var client = new RestClient("https://api-sandbox.yousign.app/v3/");

// Create the upload request
var request = new RestRequest("documents", Method.Post);

// IMPORTANT: set the correct header
request.AddHeader("Content-Type", "multipart/form-data");
request.AddHeader("Accept", "application/json");
request.AddHeader("Authorization", $"Bearer {apiKey}");

request.AddParameter("nature", "signable_document");

// Add the file to the request (it must be of type application/pdf)
request.AddFile("file", filePath);

var response = client.Execute(request);

Console.WriteLine(response.Content);