private static async Task RunAsync() { //Get base uri info BaseUriInfo uriInfo = await GetBaseUri(); _apiAccessPoint = uriInfo.ApiAccessPoint; //Create Webhook WebhookCreationResponse webhookCreationResponse = await CreateWebhook(); Console.WriteLine("Webhook ID: " + webhookCreationResponse.ID); ////Upload document TransientDocumentResponse transientDocumentResponse1 = await PostTransientDocument(FilePath1); TransientDocumentResponse transientDocumentResponse2 = await PostTransientDocument(FilePath2); var docIds = new[] { transientDocumentResponse1.TransientDocumentID, transientDocumentResponse2.TransientDocumentID }; ////Create agreement and send email AgreementCreationResponse agreementCreationResponse = await PostAgreement(docIds); Console.WriteLine("Agreement ID: " + agreementCreationResponse.ID); await DownloadFile("CBJCHBCAABAAYumJeqRwtbNpk1emzfIpBCdNrw0F55e1"); //Delete Webhook if (webhookCreationResponse.IsSuccess) { await DeleteWebhook(webhookCreationResponse.ID); } }
private static async Task <TransientDocumentResponse> PostTransientDocument(string filePath) { HttpClient client = CreateClient(_apiAccessPoint); client.DefaultRequestHeaders.Add("Mime-Type", "application/pdf"); // we need to send a request with multipart/form-data ByteArrayContent byteArrayContent = new ByteArrayContent(File.ReadAllBytes(filePath)); byteArrayContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/pdf"); MultipartFormDataContent multiForm = new MultipartFormDataContent { { new StringContent(Path.GetFileName(filePath)), "File-Name" }, { byteArrayContent, "File" }, }; HttpResponseMessage responseMesage = await client.PostAsync("transientDocuments", multiForm); TransientDocumentResponse response = await HandleResponseMessageAsync <TransientDocumentResponse>(responseMesage); return(response); }