- 18 Nov 2024
- 12 Minutes à lire
- SombreLumière
- PDF
Creating a Template
- Mis à jour le 18 Nov 2024
- 12 Minutes à lire
- SombreLumière
- PDF
Java SDK.NET SDKREST APIAPEX SDK
Java SDK
To download the full code sample see our Code Share site.
Templates and Layouts fulfill the same goal of automating the e-signature process by shortening the time it takes to send documents that include several signature blocks and data fields. Templates are ideal to use at the transaction level – you can pre-define your signers, documents, signature locations and e-signature workflows to streamline the e-signature process. A Layout on the other hand, is a type of template that allows you to create pre-defined locations for your signature blocks and data fields within a document. It acts like a ‘marker’ where signature blocks and data fields will sit in the document. Layouts are helpful for users who frequently send forms that may be slightly different per recipient but signature blocks and data fields remain in the same location throughout the document. What’s more, you can use multiple Layouts per document, and apply them to individual pages within your transaction.
Finding your Templates in the UI
First, locate your templates in the OneSpan Sign Web UI. To do this, log into your OneSpan Sign account, and then click Templates. After running your code, all your templates will appear here.
Creating a New Template
The sample code below demonstrates how to create a new template, with one document and two signers.
The first step is to create your OneSpan Sign client. Make sure to replace the API_KEY, and API_URL placeholders with your values.
Then, build your document package. Once your package is built, call on your TemplateService to create your template. The following code will create a template:
EslClient eslClient = new EslClient(API_KEY, API_URL);
DocumentPackage documentPackage = newPackageNamed("My template from scratch Java SDK")
.withVisibility(Visibility.ACCOUNT)
//.withVisibility(Visibility.SENDER)
.withSigner(newSignerPlaceholder(new Placeholder("PlaceholderId1")))
.withSigner(newSignerPlaceholder(new Placeholder("PlaceholderId2")))
.withDocument(newDocumentWithName("My Document")
.fromFile("YOUR_FILE_PATH")
.withSignature(signatureFor(new Placeholder("PlaceholderId1"))
.onPage(0)
.atPosition(100, 140))
.withSignature(signatureFor(new Placeholder("PlaceholderId2"))
.onPage(0)
.atPosition(100, 205)))
.build();
PackageId templateId = eslClient.getTemplateService().createTemplate(documentPackage);
If you set the Visibility property to SENDER (Visibility.SENDER) your template will only be accessible to the sender of the package. If you wish to share your template with your other senders, you will need to change the visibility to Visibility.ACCOUNT.
Creating a New Template from a Transaction
You can also create a template by using an existing transaction as the basis for your template. For this, you will need the packageId of your transaction. Then, you call on your TemplateService to create your template.
PackageId packageId = new PackageId("d9355f04-9bb2-4219-b9fa-734f2650a939");
PackageId templateFromPackage = eslClient.getTemplateService().createTemplateFromPackage(packageId, "New Template From Package");
Results
After running your code, you will see your newly created template in your OneSpan Signaccount.
.NET SDK
To download the full code sample see our Code Share site.
Templates and Layouts fulfill the same goal of automating the e-signature process by shortening the time it takes to send documents that include several signature blocks and data fields. Templates are ideal to use at the transaction level – you can pre-define your signers, documents, signature locations and e-signature workflows to streamline the e-signature process. A Layout on the other hand, is a type of template that allows you to create pre-defined locations for your signature blocks and data fields within a document. It acts like a ‘marker’ where signature blocks and data fields will sit in the document. Layouts are helpful for users who frequently send forms that may be slightly different per recipient but signature blocks and data fields remain in the same location throughout the document. What’s more, you can use multiple Layouts per document, and apply them to individual pages within your transaction.
Finding your Templates in the UI
First, locate your templates in the OneSpan Sign Web UI. To do this, log into your OneSpan Sign account, and then click Templates. After running your code, all your templates will appear here.
Creating a New Template
The sample code below demonstrates how to create a new template, with one document and two signers.
The first step is to create your OneSpan Sign client. Make sure to replace the API_KEY, and API_URL placeholders with your values.
Then, build your document package. Once your package is built, call on your TemplateService to create your template. The following code will create a template:
EslClient eslClient = new EslClient(API_KEY, API_URL);
DocumentPackage documentPackage = PackageBuilder
.NewPackageNamed("My template from scratch .NET SDK")
.WithVisibility(Visibility.ACCOUNT)
//.WithVisibility(Visibility.SENDER)
.WithSigner(SignerBuilder.NewSignerPlaceholder(new Placeholder("PlaceholderId1")))
.WithSigner(SignerBuilder.NewSignerPlaceholder(new Placeholder("PlaceholderId2")))
.WithDocument(DocumentBuilder.NewDocumentNamed("My Document")
.FromStream(fs, DocumentType.PDF)
.WithSignature(SignatureBuilder
.SignatureFor(new Placeholder("PlaceholderId1"))
.OnPage(0)
.AtPosition(100, 140))
.WithSignature(SignatureBuilder
.SignatureFor(new Placeholder("PlaceholderId2"))
.OnPage(0)
.AtPosition(100, 205)))
.Build();
PackageId templateId = eslClient.CreateTemplate(documentPackage);
If you set the Visibility property to SENDER (Visibility.SENDER) your template will only be accessible to the sender of the package. If you wish to share your template with your other senders, you will need to change the visibility to Visibility.ACCOUNT.
Creating a New Template from a Transaction
You can also create a template by using an existing transaction as the basis for your template. For this, you will need the packageId of your transaction. Then, you call on your TemplateService to create your template.
PackageId packageId = new PackageId("d9355f04-9bb2-4219-b9fa-734f2650a939");
PackageId templateFromPackage = eslClient.CreateTemplateFromPackage(packageId, "New Template From Package");
Results
After running your code, you will see your newly created template in your OneSpan Signaccount.
REST API
To download the full code sample see our Code Share site.
Templates and Layouts fulfill the same goal of automating the e-signature process by shortening the time it takes to send documents that include several signature blocks and data fields. Templates are ideal to use at the transaction level – you can pre-define your signers, documents, signature locations and e-signature workflows to streamline the e-signature process. A Layout on the other hand, is a type of template that allows you to create pre-defined locations for your signature blocks and data fields within a document. It acts like a ‘marker’ where signature blocks and data fields will sit in the document. Layouts are helpful for users who frequently send forms that may be slightly different per recipient but signature blocks and data fields remain in the same location throughout the document. What’s more, you can use multiple Layouts per document, and apply them to individual pages within your transaction.
Finding your Templates in the UI
First, locate your templates in the OneSpan Sign Web UI. To do this, log into your OneSpan Sign account, and then click Templates. After running your code, all your templates will appear here.
Creating a New Template
The sample code below demonstrates how to create a new template, with one document and two signers.
The sample JSON code below can be included in your multi-part form POST request to create a new template. For more information on multi-part forms, see Creating and Sending a Transaction.
This JSON request payload contains many empty properties that are not necessary for creating a new template. They are included here to give you a list of options that are available, and to demonstrate how they are parsed in the JSON.
HTTP Request
POST /api/packages
HTTP Headers
Accept: application/json
Content-Type: multipart/form-data
Authorization: Basic api_key
Request Payload
------WebKitFormBoundary1bNO60n7FqP5WO4t Content-Disposition: form-data; name="file"; file------WebKitFormBoundary1bNO60n7FqP5WO4t
Content-Disposition: form-data; name="file"; filename="testDocumentExtraction.pdf"
Content-Type: application/pdf
%PDF-1.5
%µµµµ
1 0 obj
<>>>
endobj....
------WebKitFormBoundary1bNO60n7FqP5WO4t
Content-Disposition: form-data; name="payload"
{
"name": "My template from scratch REST",
"visibility": "ACCOUNT",
"description": "",
"roles": [
{
"name": "PlaceholderId1",
"index": 0,
"id": "PlaceholderId1"
},
{
"name": "PlaceholderId2",
"index": 0,
"id": "PlaceholderId2"
}
],
"type": "TEMPLATE",
"due": null,
"autocomplete": true,
"emailMessage": "",
"documents": [
{
"approvals": [
{
"role": "PlaceholderId1",
"fields": [
{
"page": 0,
"subtype": "FULLNAME",
"width": 200,
"binding": null,
"extract": false,
"left": 175,
"top": 165,
"validation": null,
"height": 50,
"data": null,
"type": "SIGNATURE",
"value": ""
}
]
},
{
"role": "PlaceholderId2",
"fields": [
{
"page": 0,
"subtype": "FULLNAME",
"width": 200,
"binding": null,
"extract": false,
"extractAnchor": null,
"left": 550,
"top": 165,
"validation": null,
"height": 50,
"data": null,
"type": "SIGNATURE",
"value": ""
}
]
}
],
"name": "YOUR_FILE_NAME"
}
]
}
------WebKitFormBoundary1bNO60n7FqP5WO4t--
For a complete description of each field, see the Request Payload table below.
Response Payload
{
"id": "9sKhW-h-qS9m6Ho3zRv3n2a-rkI="
}
If you set the Visibility property to SENDER (Visibility.SENDER) your template will only be accessible to the sender of the package. If you wish to share your template with your other senders, you will need to change the visibility to Visibility.ACCOUNT.
Creating a New Template from a Transaction
You can also create a template by using an existing transaction as the basis for your template. For this, you will need the packageId of your transaction.
HTTP Request
POST api/packages/{packageId}/clone
HTTP Headers
Accept: application/json
Content-Type: application/json
Authorization: Basic api_key
Request Payload
{
"name": "your_cloned_template",
"description": "",
"emailMessage": "",
"autocomplete": true,
"settings": {
"ceremony": {
"inPerson": false
}
},
"type": "TEMPLATE",
"sender": {
"lastName": "Sender_Last_Name",
"firstName": "Sender_First_Name",
"email": "first.signer@example.com"
},
"visibility": "ACCOUNT",
"due": null,
"language": "en"
}
Results
After running your code, you will see your newly created template in your OneSpan Signaccount.
Request Payload Table
Property | Type | Editable | Required | Default | Sample Values |
---|---|---|---|---|---|
status | string | Yes | No | DRAFT | DRAFT / SENT / COMPLETED / ARCHIVED / DECLINED / OPTED_OUT / EXPIRED |
autoComplete | boolean | Yes | No | true | true / false |
type | string | Yes | No | PACKAGE | PACKAGE / TEMPLATE / LAYOUT |
name | string | Yes | Yes | n/a | Document Attributes Example |
trashed | boolean | Yes | No | false | true / false |
visibility | string | Yes | No | ACCOUNT | ACCOUNT / SENDER |
emailMessage | string | Yes | No | n/a | Please sign at the earliest convenience. |
description | string | Yes | No | n/a | This template has been created from scratch |
documents | |||||
name | string | Yes | No | n/a | sample doc |
approvals | |||||
fields | |||||
subtype | string | Yes | No | n/a | FULLNAME / INITIALS / CAPTURE / MOBILE_CAPTURE / LABEL / TEXTFIELD / TEXTAREA / CHECKBOX / DATE / RADIO / LIST |
type | string | Yes | No | n/a | SIGNATURE / INPUT |
binding | string | Yes | No | null | {approval.signed} / {signer.title} / {signer.name} / {signer.company} |
extract | boolean | Yes | No | false | true / false |
height | integer | Yes | No | 50 | 50 / 100 / 150 ... |
left | integer | Yes | No | 0 | 50 / 100 / 150 ... |
page | integer | Yes | No | 0 | 0 / 1 / 2 ... |
top | integer | Yes | No | 0 | 50 / 100 / 150 ... |
width | integer | Yes | No | 200 | 50 / 100 / 150 ... |
role | string | Yes | No | n/a | Client1 |
roles | |||||
id | string | Yes | No | n/a | Client1 |
name | string | Yes | No | n/a | Client1 |
type | string | Yes | No | SIGNER | SIGNER / SENDER |
signers | |||||
string | Yes | Yes | n/a | preparer.email@example.com | |
firstName | string | Yes | Yes | n/a | John |
lastName | string | Yes | Yes | n/a | Smith |
phone | string | Yes | No | n/a | 514-555-8888 |
id | string | Yes | No | n/a | Client1 |
company | string | Yes | No | n/a | Acme Inc. |
title | string | Yes | No | n/a | Managing Director |
APEX SDK
To download the full code sample see our Code Share site.
Templates and Layouts fulfill the same goal of automating the e-signature process by shortening the time it takes to send documents that include several signature blocks and data fields. Templates are ideal to use at the transaction level – you can pre-define your signers, documents, signature locations and e-signature workflows to streamline the e-signature process. A Layout on the other hand, is a type of template that allows you to create pre-defined locations for your signature blocks and data fields within a document. It acts like a ‘marker’ where signature blocks and data fields will sit in the document. Layouts are helpful for users who frequently send forms that may be slightly different per recipient but signature blocks and data fields remain in the same location throughout the document. What’s more, you can use multiple Layouts per document, and apply them to individual pages within your transaction.
Finding your Templates in the UI
First, locate your templates in the OneSpan Sign Web UI. To do this, log into your OneSpan Sign account, and then click Templates. After running your code, all your templates will appear here.
Creating a New Template
The sample code below demonstrates how to create a new template, with one document and two signers.
ESignLiveSDK sdk = new ESignLiveSDK();
ESignLiveAPIObjects.Package_x pkg = new ESignLiveAPIObjects.Package_x();
pkg.name = 'Create Template From Scratch - ' + Datetime.now().format();
// Set as template
pkg.type = ESignLiveAPIObjects.PackageType.TEMPLATE;
// Create Template
String packageId = sdk.createPackage(pkg);
System.debug('PackageId: ' + packageId);
// Add Signer
String placeholder1Id = 'placeholder1';
ESignLiveAPIObjects.Role placeholder1 = new ESignLiveAPIObjects.Role();
placeholder1.id = placeholder1Id;
placeholder1.name = placeholder1Id;
sdk.helper.createRole(packageId, placeholder1);
// Add Document
StaticResource sr = [SELECT Id, Body FROM StaticResource WHERE Name = 'testdoc1' LIMIT 1];
Map<String, Blob> doc = new Map<String, Blob>();
doc.put('Sample Document', sr.Body);
ESignLiveAPIObjects.Document document = new ESignLiveAPIObjects.Document();
document.name = 'Sample Contract';
document.id = 'document1';
sdk.createDocuments(packageId, document, doc);
// Add Signature
ESignLiveAPIObjects.Field field = new ESignLiveAPIObjects.Field();
field.left = 208;
field.width = 200;
field.height = 50;
field.top = 518;
field.page = 0;
field.subtype = 'CAPTURE';
field.type = 'SIGNATURE';
ESignLiveAPIObjects.Approval approval = new ESignLiveAPIObjects.Approval();
approval.fields = new List<ESignLiveAPIObjects.Field>{field};
approval.role = placeholder1Id;
String signatureResponse = sdk.addSignature(packageId, 'document1', approval);
Creating a New Template from a Transaction
You can also create a template by using an existing transaction as the basis for your template. For this, you will need the packageId of your transaction. Then, you call on your sdk.helper to create your template.
ESignLiveAPIObjects.Package_x template = new ESignLiveAPIObjects.Package_x();
template.name = 'Create Template From Package - ' + Datetime.now().format();
template.type = ESignLiveAPIObjects.PackageType.TEMPLATE;
template = sdk.helper.createPackageFromTemplate(template, packageId);
System.debug('template id: ' + template.id);
Create package from template and create template from package share the same function.
Results
After running your code, you will see your newly created template in your OneSpan Sign account.