diff --git a/examples/BoldSign.Examples.csproj b/examples/BoldSign.Examples.csproj
index c8dff02..36640cd 100644
--- a/examples/BoldSign.Examples.csproj
+++ b/examples/BoldSign.Examples.csproj
@@ -5,9 +5,14 @@
BoldSign.Examples
+
+ false
+ true
+
+
-
-
+
+
diff --git a/examples/BrandingExamples.cs b/examples/BrandingExamples.cs
index 17651fc..d891f90 100644
--- a/examples/BrandingExamples.cs
+++ b/examples/BrandingExamples.cs
@@ -1,4 +1,5 @@
-using BoldSign.Api;
+using System.IO;
+using BoldSign.Api;
using BoldSign.Model;
namespace BoldSign.Examples
@@ -41,14 +42,27 @@ public void ResetDefaultBrand()
///
public BrandingData CreateBrand()
{
+ var fileBytes = File.ReadAllBytes("assets/sample.jpg");
+ var stream = new MemoryStream(fileBytes);
+
var createBrandData = new BrandSettings()
{
// This is an example brand settings data to create, add your own brand settings upon usage.
BrandName = "Brand from SDK",
- BrandLogo = new DocumentFileBytes
+ // BrandLogo = new ImageFileBytes()
+ // {
+ // ContentType = "image/jpeg",
+ // FileBytes = fileBytes,
+ // },
+ // BrandLogo = new ImageFileStream()
+ // {
+ // FileStream = stream,
+ // ContentType = "image/jpeg",
+ // },
+ BrandLogo = new ImageFilePath()
{
- ContentType = "image/jpg",
- FileName = "assets/sample.jpg",
+ FilePath = "assets/sample.jpg",
+ ContentType = "image/jpeg",
},
CombineAuditTrail = false,
IsDefault = false,
@@ -60,6 +74,11 @@ public BrandingData CreateBrand()
ButtonColor = "#00BDD4",
ButtonTextColor = "#FFFFFF",
RedirectUrl = "https://app.boldsign.com/dashboard",
+ AllowCustomFieldCreation = false,
+ ShowBuiltInFormFields = true,
+ ShowSharedCustomFields = false,
+ HideDecline = false,
+ HideSave = false,
};
var result = this.BrandingClient.CreateBrand(createBrandData);
return result;
@@ -71,15 +90,27 @@ public BrandingData CreateBrand()
public BrandingData EditBrand()
{
string brandId = "Your brand-id";
+ var fileBytes = File.ReadAllBytes("assets/sample.jpg");
+ var stream = new MemoryStream(fileBytes);
var editBrandData = new BrandSettings()
{
// This is an example brand settings data to edit, add your own brand settings upon usage.
BrandName = "Brand edit from SDK",
- BrandLogo = new DocumentFileBytes
+ // BrandLogo = new ImageFileBytes()
+ // {
+ // ContentType = "image/jpeg",
+ // FileBytes = fileBytes,
+ // },
+ // BrandLogo = new ImageFileStream()
+ // {
+ // FileStream = stream,
+ // ContentType = "image/jpeg",
+ // },
+ BrandLogo = new ImageFilePath()
{
- ContentType = "image/jpg",
- FileName = "assets/sample.jpg",
+ FilePath = "assets/sample.jpg",
+ ContentType = "image/jpeg",
},
CombineAuditTrail = false,
IsDefault = false,
@@ -104,5 +135,17 @@ public BrandingRecords ListBrand()
var brandRecords = this.BrandingClient.ListBrand();
return brandRecords;
}
+
+ ///
+ /// Get the brand.
+ ///
+ public BrandDetails GetBrand()
+ {
+ // This is an example brand id, add your own brand id upon usage.
+ var brandId = "your brand-id";
+
+ var brandSettings = this.BrandingClient.GetBrandDetails(brandId);
+ return brandSettings;
+ }
}
}
\ No newline at end of file
diff --git a/examples/ContactExamples.cs b/examples/ContactExamples.cs
new file mode 100644
index 0000000..3eb72d3
--- /dev/null
+++ b/examples/ContactExamples.cs
@@ -0,0 +1,97 @@
+namespace BoldSign.Examples
+{
+ using System.Collections.Generic;
+ using BoldSign.Api;
+ using BoldSign.Api.Model;
+ using BoldSign.Model;
+ using System.Threading.Tasks;
+
+ ///
+ /// The create user examples.
+ ///
+ public class ContactExamples
+ {
+ private readonly ContactClient ContactClient;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The create user api.
+ public ContactExamples(ContactClient ContactClient)
+ {
+ this.ContactClient = ContactClient;
+ }
+
+ ///
+ /// Get contact list
+ ///
+ public ContactsList ContactList()
+ {
+ var response = this.ContactClient.ListContacts(1, 10, "", ContactType.AllContacts);
+ return response;
+ }
+
+ ///
+ /// Delete Contact details
+ ///
+ public void DeleteContact()
+ {
+ // This is an example contact id, add your own brand id upon usage.
+ var id = "contact-Id";
+ this.ContactClient.DeleteContact(id);
+ }
+
+ ///
+ /// Create Contact details
+ ///
+ public CreatedContact CreateContact()
+ {
+ var contactsDetailsList = new List();
+ ContactDetails contactsDetails = new ContactDetails()
+ {
+ Email = "test1711@gmail.com",
+ Name = "API-SDK_Test",
+ PhoneNumber = new PhoneNumber()
+ {
+ CountryCode = "91",
+ Number = "6547456721"
+ },
+ CompanyName = "1711",
+ JobTitle = "Test"
+ };
+
+ contactsDetailsList.Add(contactsDetails);
+ var response = this.ContactClient.CreateContact(contactsDetailsList);
+ return response;
+ }
+
+ ///
+ /// Update Contact details
+ ///
+ public void UpdateContact()
+ {
+ string id = "6797a07d-26d7-41fa-b3a8-c8f72378a7a6c_gEkPI";
+ var updateContact = new ContactDetails()
+ {
+ Email = "test1711@gmail.com",
+ Name = "Test_Engineer",
+ PhoneNumber = new PhoneNumber()
+ {
+ CountryCode = "91",
+ Number = "9182736450"
+ },
+ CompanyName = "1711_1802",
+ JobTitle = "Test"
+ };
+
+ this.ContactClient.UpdateContact(id, updateContact);
+ }
+
+ public ContactsDetails GetContact()
+ {
+ string id = "6797a07d-26d7-41fa-b3a8-c8f72378a7a6c_KRMh4";
+ var response = this.ContactClient.GetContact(id);
+ return response;
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/CustomFieldExamples.cs b/examples/CustomFieldExamples.cs
new file mode 100644
index 0000000..4fe22ab
--- /dev/null
+++ b/examples/CustomFieldExamples.cs
@@ -0,0 +1,90 @@
+using BoldSign.Api;
+using BoldSign.Model;
+using System;
+
+namespace BoldSign.Examples
+{
+ ///
+ /// The Custom Field Examples.
+ ///
+ public class CustomFieldExamples
+ {
+ private readonly ICustomFieldClient CustomFieldClient;
+
+ public CustomFieldExamples(ICustomFieldClient customFieldClient) => this.CustomFieldClient = customFieldClient;
+
+ ///
+ /// Creates a custom field for the specified brand.
+ ///
+ public void CreateCustomField()
+ {
+ var brandCustomFieldDetails = new BrandCustomFieldDetails()
+ {
+ FieldName = "Field Name",
+ FieldDescription = "Description",
+ FieldOrder = 1,
+ BrandId = "Brand Id",
+ FormField = new CustomFormField(
+ type: FieldType.Signature,
+ isRequired: true),
+ };
+
+ this.CustomFieldClient.CreateCustomField(brandCustomFieldDetails);
+ }
+
+ ///
+ /// Edits a custom field for the specified brand.
+ ///
+ public void EditCustomField()
+ {
+ var brandCustomFieldDetails = new BrandCustomFieldDetails()
+ {
+ FieldName = "Field Name",
+ FieldDescription = "Description",
+ FieldOrder = 1,
+ BrandId = "Brand Id",
+ FormField = new CustomFormField(
+ type: FieldType.Signature,
+ isRequired: true),
+ };
+
+ var customFieldId = "custom field id";
+
+ this.CustomFieldClient.EditCustomField(customFieldId, brandCustomFieldDetails);
+ }
+
+ ///
+ /// Deletes a custom field for the specified brand.
+ ///
+ public void DeleteCustomField()
+ {
+ var customFieldId = "custom field id";
+
+ this.CustomFieldClient.DeleteCustomField(customFieldId);
+ }
+
+ ///
+ /// Gets the all custom field for the specified brand.
+ ///
+ public void GetCustomField()
+ {
+ var brandId = "Brand Id";
+
+ this.CustomFieldClient.GetBrandBasedCustomFields(brandId);
+ }
+
+ ///
+ /// Generates a URL to embed manipulation of custom field process.
+ ///
+ public void CreateEmbeddedCustomFieldUrl()
+ {
+ var embeddedCustomFieldDetails = new EmbeddedCustomFieldDetails()
+ {
+ BrandId = "Brand Id",
+ LinkValidTill = DateTime.UtcNow.AddDays(1),
+ };
+
+ this.CustomFieldClient.CreateEmbeddedCustomFieldUrl(embeddedCustomFieldDetails);
+ }
+ }
+}
\ No newline at end of file
diff --git a/examples/DocumentExamples.cs b/examples/DocumentExamples.cs
index 08178b4..932e445 100644
--- a/examples/DocumentExamples.cs
+++ b/examples/DocumentExamples.cs
@@ -1,3 +1,5 @@
+using BoldSign.Api.Model;
+
namespace BoldSign.Examples
{
using BoldSign.Api;
@@ -7,6 +9,7 @@ namespace BoldSign.Examples
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
+ using System.Linq;
///
/// The document examples.
@@ -40,7 +43,7 @@ public TeamDocumentRecords ListTeamDocuments()
return documents;
}
-
+
///
/// Lists the behalf documents.
///
@@ -307,7 +310,7 @@ public void ChangeRecipient()
// This is an example document id, add your own document id upon usage.
var documentId = "1ace7c82-6770-4d03-b514-b593e20c4550";
- this.DocumentClient.ChangeRecipient(documentId, "signer1@email.com", "wrong email", "signer2", "signer2@email.com");
+ this.DocumentClient.ChangeRecipient(documentId, "signer1@gmail.com", "wrong email", "signer2", "signer2@email.com");
}
///
@@ -347,10 +350,11 @@ public async Task CreateDocument()
List formFeilds = new List();
formFeilds.Add(new FormField(
name: "Sign",
- type: FieldType.Signature,
+ type: FieldType.CheckBox,
pageNumber: 1,
isRequired: true,
bounds: new Rectangle(x: 50, y: 50, width: 200, height: 30)));
+
var documentDetails = new SendForSign
{
Title = "Sent from API SDK",
@@ -359,15 +363,92 @@ public async Task CreateDocument()
Signers = new List
{
new DocumentSigner(
- name: "Signer Name 1",
- emailAddress: "signer1@email.com",
+ signerName: "Signer Name 1",
+ signerType: SignerType.Signer,
+ signerEmail: "ranjitha.vazhivittan+1@syncfusion.com",
+ signerOrder: 1,
+ authenticationCode: "123",
+ privateMessage: "This is private message for signer",
+ formFields: formFeilds,
+ locale: Locales.EN)
+ },
+ };
+
+ // document read from local as byte array
+ var fileBytes = File.ReadAllBytes("doc-1.pdf");
+
+ // document read from local as stream
+ using var fs = File.OpenRead("doc-2.pdf");
+
+ documentDetails.Files = new List
+ {
+ new DocumentFilePath
+ {
+ ContentType = "application/pdf",
+ // directly provide file path
+ FilePath = "doc-1.pdf",
+ },
+ new DocumentFileBytes
+ {
+ ContentType = "application/pdf",
+ FileData = fileBytes,
+ FileName = "doc-1.pdf",
+ },
+ new DocumentFileStream
+ {
+ ContentType = "application/pdf",
+ FileData = fs,
+ FileName = "doc-2.pdf",
+ },
+ };
+
+ var documentCreated = this.DocumentClient.SendDocument(documentDetails);
+
+ return documentCreated;
+ }
+
+ ///
+ /// Creates the document with Radio button.
+ ///
+ public async Task CreateDocumentWithRadioButtonField()
+ {
+ var radioButtonFields = new List
+ {
+ new RadioButtonField(
+ id: "Tamil_Language",
+ pageNumber: 1,
+ isRequired: true,
+ label: "Tamil",
+ groupName: "Language",
+ bounds: new Rectangle(x: 50, y: 200, width: 20, height: 20)),
+ new RadioButtonField(
+ id: "Maths_Language",
+ pageNumber: 1,
+ isRequired: true,
+ label: "Maths",
+ groupName: "Language",
+ bounds: new Rectangle(x: 150, y: 200, width: 20, height: 20)),
+ };
+
+ var documentDetails = new SendForSign
+ {
+ Title = "Sent from API SDK",
+ Message = "This is document message sent from API SDK",
+ EnableSigningOrder = true,
+ Signers = new List
+ {
+ new DocumentSigner(
+ signerName: "Signer Name 1",
+ signerEmail: "signer1@email.com",
signerOrder: 1,
authenticationCode: "123",
signerType: SignerType.Signer,
privateMessage: "This is private message for signer",
- formFields:formFeilds),
+ formFields: radioButtonFields.Cast().ToList(),
+ locale: Locales.EN),
},
};
+
// document read from local as byte array
var fileBytes = File.ReadAllBytes("doc-1.pdf");
@@ -425,13 +506,14 @@ public async Task CreateDocumentWithFileUrl()
Signers = new List
{
new DocumentSigner(
- name: "Signer Name 1",
- emailAddress: "signer1@email.com",
+ signerName: "Signer Name 1",
+ signerType: SignerType.Signer,
+ signerEmail: "signer1@email.com",
signerOrder: 1,
authenticationCode: "123",
- signerType: SignerType.Signer,
privateMessage: "This is private message for signer",
- formFields:formFields),
+ formFields:formFields,
+ locale: Locales.EN),
},
};
@@ -468,13 +550,14 @@ public async Task EmbeddedSendDocument()
Signers = new List
{
new DocumentSigner(
- name: "Signer Name 1",
- emailAddress: "signer1@email.com",
+ signerName: "Signer Name 1",
+ signerType: SignerType.Signer,
+ signerEmail: "signer1@email.com",
signerOrder: 1,
authenticationCode: "123",
- signerType: SignerType.Signer,
privateMessage: "This is private message for signer",
- formFields: formFields),
+ formFields: formFields,
+ locale: Locales.EN),
},
Files = new List
{
@@ -511,6 +594,28 @@ public void RemoveAuthentication()
this.DocumentClient.RemoveAuthentication(documentId, "signer1@email.com", 1);
}
+
+ ///
+ /// pre fill form field.
+ ///
+ public async Task PrefillFieldsAsync()
+ {
+ // This is an example document id, add your own document id upon usage.
+ var documentId = "702d9699-3f01-4a46-ac70-c0545cff73b7";
+ var prefillFieldRequest = new PrefillFieldRequest(documentId)
+ {
+ Fields = new List()
+ {
+ new PrefillField()
+ {
+ Id = "checkbox_v4tuQ",
+ Value = "off"
+ }
+ },
+ };
+
+ await this.DocumentClient.PrefillFieldsAsync(prefillFieldRequest);
+ }
}
}
diff --git a/examples/PlanExamples.cs b/examples/PlanExamples.cs
index 9ccaab8..cba037b 100644
--- a/examples/PlanExamples.cs
+++ b/examples/PlanExamples.cs
@@ -9,7 +9,6 @@
using BoldSign.Api;
using BoldSign.Api.Resources;
using BoldSign.Model;
- using RestSharp;
///
/// The plan examples.
diff --git a/examples/Program.cs b/examples/Program.cs
index 07848c7..3cade36 100644
--- a/examples/Program.cs
+++ b/examples/Program.cs
@@ -20,6 +20,7 @@ private static async Task Main(string[] args)
var userExamples = new UserExamples(new UserClient(apiClient));
var brandingExamples = new BrandingExamples(new BrandingClient(apiClient));
var senderIdentityExamples = new SenderIdentityExamples(new SenderIdentityClient(apiClient));
+ var customFieldExamples = new CustomFieldExamples(new CustomFieldClient(apiClient));
await documentExamples.CreateDocument().ConfigureAwait(false);
// webhook event helpers
diff --git a/examples/SenderIdentityExamples.cs b/examples/SenderIdentityExamples.cs
index 58352e4..5d56b8e 100644
--- a/examples/SenderIdentityExamples.cs
+++ b/examples/SenderIdentityExamples.cs
@@ -51,7 +51,7 @@ public void UpdateSenderIdentity()
///
public void ResendSenderIdentityInvitation()
{
- var email = "identity@email.com";
+ var email = "identity@gmail.com";
this.senderIdentityClient.ResendInvitation(email);
}
@@ -60,7 +60,7 @@ public void ResendSenderIdentityInvitation()
///
public void RerequestSenderIdentity()
{
- var email = "identity@email.com";
+ var email = "identity@gmail.com";
this.senderIdentityClient.RerequestSenderIdentity(email);
}
@@ -69,7 +69,7 @@ public void RerequestSenderIdentity()
///
public void DeleteSenderIdentity()
{
- var email = "identity@email.com";
+ var email = "identity@gmail.com";
this.senderIdentityClient.DeleteSenderIdentity(email);
}
diff --git a/examples/TemplateExamples.cs b/examples/TemplateExamples.cs
index bbf3ce3..1a1436e 100644
--- a/examples/TemplateExamples.cs
+++ b/examples/TemplateExamples.cs
@@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
+ using System.Linq;
///
/// The template examples.
@@ -41,6 +42,46 @@ public void DeleteTemplate()
this.templateApi.DeleteTemplate(templateId);
}
+
+ ///
+ /// Edits a template.
+ ///
+ /// A task.
+ public async Task EditTemplate()
+ {
+ // This is an example template id, add your own template id upon usage.
+ var templateId = "cc8e9326-c0a9-4caf-808f-17d9499d1abc";
+ var formFields = new List
+ {
+ new FormField(
+ id: "Sign",
+ type: FieldType.Signature,
+ pageNumber: 1,
+ isRequired: true,
+ bounds: new Rectangle(x: 50, y: 50, width: 200, height: 30)),
+ };
+ var editTemplateRequest = new EditTemplateRequest(templateId)
+ {
+ DocumentTitle = "new title",
+ Roles = new List
+ {
+ new TemplateRole(
+ 1,
+ name: "RoleName",
+ defaultSignerEmail: "signer1@email.com",
+ defaultSignerName: "signer1",
+ signerOrder: 1,
+ signerType: SignerType.Signer,
+ formFields: formFields,
+ locale: Locales.EN),
+ },
+ EnableSigningOrder = true,
+
+
+ };
+
+ await this.templateApi.EditTemplateAsync(editTemplateRequest).ConfigureAwait(false);
+ }
///
/// Creates the document using template without any customization.
@@ -71,16 +112,27 @@ public DocumentCreated CreateDocumentWithCustomRoles()
// This is an example document id, add your own document id upon usage.
var templateId = "949ebf20-45a8-4a3e-91a9-68e9540e0020";
- var roles = new List
+ var formFields = new List
{
- new Roles
- {
- RoleIndex = 1,
- SignerEmail = "signer1@email.com",
- SignerName = "Signer Name",
- },
+ new FormField(
+ id: "Sign",
+ type: FieldType.Signature,
+ pageNumber: 1,
+ isRequired: true,
+ bounds: new Rectangle(x: 50, y: 50, width: 200, height: 30)),
};
+ var roles = new List
+ {
+ new Roles(
+ roleSignerIndex: 1,
+ roleSignerEmailAddress: "signer1@email.com",
+ roleSignerName: "signer1",
+ signerOrder: 1,
+ signerType: SignerType.Signer,
+ formFields: formFields,
+ locale: Locales.EN)
+ };
var templateDetails = new SendForSignFromTemplate(
templateId: templateId,
title: "Document from Template",
@@ -152,6 +204,52 @@ public TemplateProperties GetProperties()
return templateProperties;
}
+ ///
+ /// Add the template tag.
+ ///
+ public void AddTemplateTags()
+ {
+ TemplateTag addTags = new TemplateTag()
+ {
+ TemplateId = "6c386439-7f23-405a-98a3-a1bf3451a1ab",
+ TemplateLabels = new List
+ {
+ "test",
+ "test1"
+ },
+ DocumentLabels = new List
+ {
+ "test2",
+ "test3"
+ }
+ };
+
+ this.templateApi.AddTag(addTags);
+ }
+
+ ///
+ /// Delete the template properties.
+ ///
+ public void DeleteTags()
+ {
+ TemplateTag addTags = new TemplateTag()
+ {
+ TemplateId = "6c386439-7f23-405a-98a3-a1bf3451a1ab",
+ TemplateLabels = new List
+ {
+ "test",
+ "test1"
+ },
+ DocumentLabels = new List
+ {
+ "test2",
+ "test3"
+ }
+ };
+
+ this.templateApi.DeleteTag(addTags);
+ }
+
///
/// Generates a edit URL to embeds template edit process into your application.
///
@@ -192,29 +290,116 @@ public async Task CreateTemplate()
isRequired: true,
bounds: new Rectangle(x: 50, y: 50, width: 200, height: 30)),
};
+
+
+ var templateDetails = new CreateTemplateRequest
+ {
+ Title = "Template created from API SDK",
+ Description = "The is a template created to get a quick contract sign.",
+ EnableSigningOrder = true,
+ AutoDetectFields = true,
+ Roles = new List
+ {
+ new TemplateRole(
+ 1,
+ name: "RoleName",
+ defaultSignerEmail: "signer1@email.com",
+ defaultSignerName: "signer1",
+ signerOrder: 1,
+ signerType: SignerType.Signer,
+ formFields: formFields,
+ locale: Locales.EN)
+ },
+ DocumentInfo = new List
+ {
+ new DocumentInfo(
+ documentTitle: "Sent using template created from API SDK",
+ documentDescription: "This is document message sent from API SDK",
+ locale: Locales.EN),
+ }
+ };
+
+ // document read from local as byte array
+ var fileBytes = await File.ReadAllBytesAsync("doc-1.pdf");
+
+ // document read from local as stream
+ await using var fs = File.OpenRead("doc-2.pdf");
+
+ templateDetails.Files = new List
+ {
+ new DocumentFilePath
+ {
+ ContentType = "application/pdf",
+
+ // directly provide file path
+ FilePath = "doc-1.pdf",
+ },
+ new DocumentFileBytes
+ {
+ ContentType = "application/pdf",
+ FileData = fileBytes,
+ FileName = "doc-1.pdf",
+ },
+ new DocumentFileStream
+ {
+ ContentType = "application/pdf",
+ FileData = fs,
+ FileName = "doc-2.pdf",
+ },
+ };
+
+ var templateCreated = await this.templateApi.CreateTemplateAsync(templateDetails);
+
+ return templateCreated;
+ }
+
+ ///
+ /// Creates the template.
+ ///
+ public async Task CreateTemplateWithRadioButtonField()
+ {
+ var radioButtonFields = new List
+ {
+ new RadioButtonField(
+ id: "Tamil_Language",
+ pageNumber: 1,
+ isRequired: true,
+ label: "Tamil",
+ groupName: "Language",
+ bounds: new Rectangle(x: 50, y: 100, width: 20, height: 20)),
+ new RadioButtonField(
+ id: "Maths_Language",
+ pageNumber: 1,
+ isRequired: true,
+ label: "Maths",
+ groupName: "Language",
+ bounds: new Rectangle(x: 150, y: 200, width: 20, height: 20)),
+ };
var templateDetails = new CreateTemplateRequest
{
Title = "Template created from API SDK",
Description = "The is a template created to get a quick contract sign.",
EnableSigningOrder = true,
+ AutoDetectFields = true,
Roles = new List
{
new TemplateRole(
- index: 1,
+ roleIndex: 1,
name: "RoleName",
defaultSignerEmail: "signer1@email.com",
defaultSignerName: "signer1",
signerOrder: 1,
signerType: SignerType.Signer,
- formFields: formFields),
+ formFields: radioButtonFields.Cast().ToList(),
+ locale: Locales.EN)
},
DocumentInfo = new List
{
new DocumentInfo(
- title: "Sent using template created from API SDK",
- language: Languages.English,
- description: "This is document message sent from API SDK"),
+ documentTitle: "Sent using template created from API SDK",
+ locale: Locales.EN,
+ documentDescription: "This is document message sent from API SDK"),
}
};
@@ -271,19 +456,27 @@ public async Task EmbeddedCreateTemplate()
{
Title = "Template created from API SDK",
Description = "The is a template created to get a quick contract sign.",
- DocumentTitle = "Sent using template created from API SDK",
DocumentMessage = "This is document message sent from API SDK",
EnableSigningOrder = true,
+ AutoDetectFields = true,
Roles = new List
{
new TemplateRole(
- index: 1,
+ 1,
name: "Engineer",
defaultSignerEmail: "signer1@email.com",
defaultSignerName: "signer1",
signerOrder: 1,
signerType: SignerType.Signer,
- formFields: formFields),
+ formFields: formFields,
+ locale: Locales.EN),
+ },
+ DocumentInfo = new List
+ {
+ new DocumentInfo(
+ documentTitle: "Sent using template created from API SDK",
+ locale:Locales.EN,
+ documentDescription: "This is document message sent from API SDK"),
},
Files = new List
{
@@ -310,5 +503,116 @@ public async Task EmbeddedCreateTemplate()
// url to send the document from your web application
var templateCreateUrl = templateCreated.CreateUrl;
}
+
+ ///
+ /// Creates the document using merge the templates.
+ ///
+ /// A DocumentCreated.
+ public DocumentCreated MergeAndSend()
+ {
+ // This is list of example template ids, add your own template ids created from the web app upon usage.
+ string[] templateIds = { "templateId1", "templateId2", "moreTemplateIds..." };
+
+ var formFields = new List
+ {
+ new FormField(
+ id: "Sign1",
+ type: FieldType.Signature,
+ pageNumber: 1,
+ isRequired: true,
+ bounds: new Rectangle(x: 50, y: 50, width: 200, height: 30))
+
+ };
+ var formFields2 = new List
+ {
+ new FormField(
+ id: "Sign2",
+ type: FieldType.Signature,
+ pageNumber: 1,
+ isRequired: true,
+ bounds: new Rectangle(x: 150, y: 150, width: 200, height: 30)),
+ };
+ var formFields3 = new List
+ {
+ new FormField(
+ id: "Sign3",
+ type: FieldType.Signature,
+ pageNumber: 1,
+ isRequired: true,
+ bounds: new Rectangle(x: 250, y: 250, width: 200, height: 30)),
+ };
+
+
+ var roles = new List
+ {
+ new Roles(
+ roleSignerIndex: 1,
+ roleSignerEmailAddress: "sign1@gmail.com",
+ roleSignerName: "sign1",
+ signerOrder: 1,
+ signerType: SignerType.Signer,
+ formFields: formFields,
+ locale: Locales.EN),
+ new Roles(
+ roleSignerIndex: 2,
+ roleSignerEmailAddress: "sign2@gmail.com",
+ roleSignerName: "sign2",
+ signerOrder: 1,
+ signerType: SignerType.Signer,
+ formFields: formFields2,
+ locale: Locales.EN),
+ new Roles(
+ roleSignerIndex: 3,
+ roleSignerEmailAddress: "sign3@gmail.com",
+ roleSignerName: "sign3",
+ signerOrder: 1,
+ signerType: SignerType.Signer,
+ formFields: formFields3,
+ locale: Locales.EN)
+ };
+
+ var templateDetails = new MergeAndSendForSign(
+ templateIds: templateIds,
+ title: "Create Document from Merged Templates",
+ message: "This is the document description",
+ roles: roles);
+
+ var documentCreated = this.templateApi.MergeAndSend(templateDetails);
+
+ return documentCreated;
+ }
+
+ ///
+ /// Remove the fields via send document using template.
+ ///
+ /// A DocumentCreated.
+ public DocumentCreated RemoveFieldsViaTemplateSend()
+ {
+ // This is an example document id, add your own template id created from the web app upon usage.
+ var templateId = "43707a56-e2e1-4bde-9ce1-1b2958fcc015";
+
+ var templateDetails = new SendForSignFromTemplate(
+ templateId: templateId,
+ title: "Document from Template",
+ message: "This document description",
+ roles:new List()
+ {
+ new Roles()
+ {
+ RoleIndex = 1,
+ SignerName = "signer",
+ SignerEmail = "signer@123.com",
+ SignerOrder = 1,
+ SignerRole = "signer",
+ SignerType = SignerType.Signer,
+ }
+ });
+ var removefields = new List();
+ removefields.Add("TextBox1");
+ templateDetails.RemoveFormFields = removefields;
+ var documentCreated = this.templateApi.SendUsingTemplate(templateDetails);
+
+ return documentCreated;
+ }
}
}
diff --git a/src/BoldSign/Api/ApiClient.cs b/src/BoldSign/Api/ApiClient.cs
index 7facdaa..d335f78 100644
--- a/src/BoldSign/Api/ApiClient.cs
+++ b/src/BoldSign/Api/ApiClient.cs
@@ -16,13 +16,17 @@ namespace BoldSign.Api
using System.Globalization;
using System.IO;
using System.Linq;
+ using System.Net;
+ using System.Net.Http;
+ using System.Net.Http.Headers;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+ using System.Web;
+ using BoldSign.Api.Extensions;
+ using BoldSign.Api.Resources;
using BoldSign.Model;
using Newtonsoft.Json;
- using RestSharp;
- using RestSharp.Extensions;
///
/// API client is mainly responsible for making the HTTP call to the API backend.
@@ -43,6 +47,13 @@ public class ApiClient
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
};
+ private List noContentMethods = new List
+ {
+ HttpMethod.Get,
+ HttpMethod.Head,
+ HttpMethod.Delete,
+ };
+ private HttpClient httpClient;
///
/// Initializes a new instance of the class
@@ -51,33 +62,36 @@ public class ApiClient
public ApiClient()
{
this.Configuration = Api.Configuration.Default;
- this.RestClient = new RestClient(this.Configuration.BasePath);
+ this.HttpClient = new HttpClient();
+ this.HttpClient.BaseAddress = new Uri(this.Configuration.BasePath);
}
///
/// Initializes a new instance of the class
- /// with default base path .
+ /// with default base path .
///
/// An instance of Configuration.
public ApiClient(Configuration config)
{
this.Configuration = config ?? Api.Configuration.Default;
- this.RestClient = new RestClient(this.Configuration.BasePath);
+ this.HttpClient = new HttpClient();
+ this.HttpClient.BaseAddress = new Uri(this.Configuration.BasePath);
}
///
/// Initializes a new instance of the class
- /// with default base path and api key. .
///
- /// An instance of Configuration.
+ /// An instance of base path.
+ /// An instance of api key.
public ApiClient(string basePath, string apiKey)
{
if (string.IsNullOrEmpty(basePath))
{
throw new ArgumentException("basePath cannot be empty");
}
- this.RestClient = new RestClient(basePath);
+ this.HttpClient = new HttpClient();
+ this.HttpClient.BaseAddress = new Uri(basePath);
this.Configuration = Api.Configuration.Default;
this.Configuration.DefaultHeader.Remove(XApiKey);
this.Configuration.DefaultHeader.Add(XApiKey, apiKey);
@@ -115,7 +129,8 @@ public ApiClient(string basePath = Api.Configuration.ApiBaseUrl)
throw new ArgumentException("basePath cannot be empty");
}
- this.RestClient = new RestClient(basePath);
+ this.HttpClient = new HttpClient();
+ this.HttpClient.BaseAddress = new Uri(basePath);
this.Configuration = Api.Configuration.Default;
}
@@ -131,61 +146,46 @@ public ApiClient(string basePath = Api.Configuration.ApiBaseUrl)
public IReadableConfiguration Configuration { get; set; }
///
- /// Gets or sets the RestClient.
- ///
- /// An instance of the RestClient
- internal RestClient RestClient { get; set; }
-
- ///
- /// Allows for extending request processing for generated code.
+ /// Gets or sets the HttpClient.
///
- /// The RestSharp request object
- private void InterceptRequest(IRestRequest request)
+ /// An instance of the HttpClient.
+ internal HttpClient HttpClient
{
- // Make this method partial, if extending or intercepting is required.
+ get => this.httpClient ?? new HttpClient();
+ set => this.httpClient = value;
}
+ // Creates and sets up a RestRequest prior to a call.
///
- /// Allows for extending response processing for generated code.
+ /// Creates and sets up a RestRequest prior to a call.
///
- /// The RestSharp request object
- /// The RestSharp response object
- private void InterceptResponse(IRestRequest request, IRestResponse response)
- {
- // Make this method partial, if extending or intercepting is required.
- }
-
- // Creates and sets up a RestRequest prior to a call.
- internal RestRequest PrepareRequest(
- string path, Method method, List> queryParams, object postBody,
- Dictionary headerParams, Dictionary formParams,
- Dictionary> fileParams, Dictionary pathParams,
- string contentType, Dictionary fileUrlsParams, Dictionary singleFileParam)
+ /// Gets or sets a path.
+ /// Gets or sets a method.
+ /// Gets or sets a queryParams.
+ /// Gets or sets a postBody.
+ /// Gets or sets a headerParams.
+ /// Gets or sets a formParams.
+ /// Gets or sets a fileParams.
+ /// Gets or sets a contentType.
+ /// Gets or sets a fileUrlParams.>
+ /// Gets or sets a singleFileParam.>
+ /// request.
+ internal HttpRequestMessage PrepareRequest(string path, HttpMethod method, List> queryParams, object postBody, Dictionary headerParams, Dictionary formParams, Dictionary> fileParams, string contentType, Dictionary fileUrlsParams, KeyValuePair singleFileParam)
{
- var request = new RestRequest(path, method);
-
- // add path parameter, if any
- foreach (var param in pathParams)
- {
- request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
- }
+ var pathUrl = BuildUri(path, queryParams);
+ var request = new HttpRequestMessage(method, pathUrl);
+ var form = new MultipartFormDataContent();
// add header parameter, if any
foreach (var param in headerParams)
{
- request.AddHeader(param.Key, param.Value);
- }
-
- // add query parameter, if any
- foreach (var param in queryParams)
- {
- request.AddQueryParameter(param.Key, param.Value);
+ request.Headers.Add(param.Key, param.Value);
}
// add form parameter, if any
foreach (var param in formParams)
{
- request.AddParameter(param.Key, param.Value);
+ form.AddFormParameter(param.Key, param.Value);
}
// add file parameter, if any
@@ -195,36 +195,93 @@ internal RestRequest PrepareRequest(
{
if (file is DocumentFilePath documentFilePath)
{
- request.AddFile(param.Key, Path.GetFullPath(documentFilePath.FilePath), documentFilePath.ContentType);
+ if (string.IsNullOrEmpty(documentFilePath.FilePath))
+ {
+ throw new ApiException(400, string.Format(CultureInfo.CurrentCulture, ApiValidationMessages.EmptyFields, nameof(documentFilePath.FilePath)));
+ }
+
+ if (string.IsNullOrEmpty(documentFilePath.ContentType))
+ {
+ throw new ApiException(422, ApiValidationMessages.UnsupportedFileType);
+ }
+
+ var fileContent = new ByteArrayContent(File.ReadAllBytes(documentFilePath.FilePath));
+ fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(documentFilePath.ContentType);
+ var fileName = Path.GetFileName(documentFilePath.FilePath);
+ form.Add(fileContent, param.Key, fileName);
}
else
{
var documentFile = GetDocumentFile(file);
- request.AddFile(param.Key, documentFile.FileData, documentFile.FileName, documentFile.ContentType);
+ if (string.IsNullOrEmpty(documentFile.FileName))
+ {
+ throw new ApiException(400, string.Format(CultureInfo.CurrentCulture, ApiValidationMessages.EmptyFields, nameof(documentFile.FileName)));
+ }
+
+ if (string.IsNullOrEmpty(documentFile.ContentType))
+ {
+ throw new ApiException(422, ApiValidationMessages.UnsupportedFileType);
+ }
+
+ var byteArrayContent = new ByteArrayContent(documentFile.FileData);
+ byteArrayContent.Headers.ContentType = MediaTypeHeaderValue.Parse(documentFile.ContentType);
+ form.Add(byteArrayContent, param.Key, documentFile.FileName);
}
}
}
- // add single file URL parameter, if any
- if (singleFileParam != null)
+ if (!string.IsNullOrEmpty(singleFileParam.Key))
{
- foreach (var param in singleFileParam)
+ var key = singleFileParam.Key;
+ if (singleFileParam.Value == null)
+ {
+ throw new ApiException((int)HttpStatusCode.BadRequest, string.Format(CultureInfo.CurrentCulture, ApiValidationMessages.EmptyFields, singleFileParam.Key));
+ }
+
+ switch (singleFileParam.Value)
{
- var documentFile = GetDocumentFile(param.Value);
- request.AddFile(param.Key, documentFile.FileName, documentFile.ContentType);
+ case ImageFileStream brandingFileStream:
+ {
+ HandleFileStream(brandingFileStream, key, form);
+ break;
+ }
+
+ case ImageFileBytes brandingFileBytes:
+ {
+ HandleFileBytes(brandingFileBytes, key, form);
+ break;
+ }
+
+ case ImageFilePath brandingFilePath:
+ {
+ HandleFilePath(brandingFilePath, key, form);
+ break;
+ }
+
+ default:
+ {
+ throw new InvalidOperationException(ApiValidationMessages.InvalidBrandFileInstance);
+ }
}
}
// add file URL parameter, if any
foreach (var param in fileUrlsParams)
{
- request.AddParameter(param.Key, param.Value);
+ form.AddFormParameter(param.Key, param.Value?.AbsoluteUri);
}
+ // http body (model or byte[]) parameter
+ if (postBody != null)
+ {
+ var requestBodyContent = new StringContent(postBody.ToString(), Encoding.UTF8, contentType);
+ request.Content = requestBodyContent;
+ return request;
+ }
- if (postBody != null) // http body (model or byte[]) parameter
+ if (!this.noContentMethods.Contains(method) && form.Any())
{
- request.AddParameter(contentType, postBody, ParameterType.RequestBody);
+ request.Content = form;
}
return request;
@@ -248,10 +305,11 @@ private static DocumentFile GetDocumentFile(IDocumentFile documentFile)
}
else if (documentFile is DocumentFileStream documentFileStream)
{
+ var bytes = documentFileStream.FileData.ReadAsBytes();
return new DocumentFile
{
ContentType = documentFileStream.ContentType,
- FileData = documentFileStream.FileData.ReadAsBytes(),
+ FileData = bytes,
FileName = documentFileStream.FileName,
};
}
@@ -269,30 +327,23 @@ private static DocumentFile GetDocumentFile(IDocumentFile documentFile)
/// Header parameters.
/// Form parameters.
/// File parameters.
- /// Path parameters.
- /// Content Type of the request
- /// File Url parameter.>
+ /// Gets or sets a contentType.
+ /// File URL parameter.
/// Single file parameter.
- /// Object
- internal object CallApi(
- string path, Method method, List> queryParams, object postBody,
- Dictionary headerParams, Dictionary formParams,
- Dictionary> fileParams, Dictionary pathParams,
- string contentType, Dictionary fileUrlParams, Dictionary singleFileParam = null)
+ /// Object.
+ internal HttpResponseMessage CallApi(string path, HttpMethod method, List> queryParams, object postBody, Dictionary headerParams, Dictionary formParams, Dictionary> fileParams, string contentType, Dictionary fileUrlParams, KeyValuePair singleFileParam = default)
{
- var request = this.PrepareRequest(
- path, method, queryParams, postBody, headerParams, formParams, fileParams,
- pathParams, contentType, fileUrlParams, singleFileParam);
-
- // set timeout
+ using var request = this.PrepareRequest(path, method, queryParams, postBody, headerParams, formParams, fileParams, contentType, fileUrlParams, singleFileParam);
- this.RestClient.Timeout = this.Configuration.Timeout;
// set user agent
- this.RestClient.UserAgent = this.Configuration.UserAgent;
+ if (this.HttpClient.DefaultRequestHeaders.UserAgent.Count == 0)
+ {
+ this.HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(this.Configuration.UserAgent);
+ }
- this.InterceptRequest(request);
- var response = this.RestClient.Execute(request);
- this.InterceptResponse(request, response);
+ this.InterceptRequest();
+ var response = this.HttpClient.SendAsync(request).GetAwaiter().GetResult();
+ this.InterceptResponse();
return response;
}
@@ -307,24 +358,21 @@ internal object CallApi(
/// Header parameters.
/// Form parameters.
/// File parameters.
- /// Path parameters.
- /// Content type.
+ /// Gets or sets a contentType.
/// File Urls parameter.
/// single file parameter.
/// The Task instance.
- internal async Task