Templates

This guide will show you how to create a template from scratch and from an existing document package.

Templates in the UI

To begin with, you should locate the templates section in your UI. After logging into your OneSpan Sign account, click on TEMPLATES in your toolbar. After running your code, you should find your saved templates here.

Capture

The Code

This segment breaks down the code section by section. You can get the full sample code from the Developer Community Code Share, here.

The sample code below creates a template from scratch, 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. Afterwards, you build your document package (transaction in the UI) with the applicable properties. Once your package is built, you call on your TemplateService to create your 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 Visibility.SENDER to your template, it means the template is only 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.

You can also create a template from an existing package. For this, you will need the packageId of your package. Then, you call on your TemlateService to create your template.

PackageId packageId = new PackageId("d9355f04-9bb2-4219-b9fa-734f2650a939");
PackageId templateFromPackage = eslClient.getTemplateService().createTemplateFromPackage(packageId, "New Template From Package" );

Running Your Code

After running your code, you should be able to see your newly created template in your OneSpan Sign account.

Capture

Get the Code

Templates in the UI

To begin with, you should locate the templates section in your UI. After logging into your OneSpan Sign account, click on TEMPLATES in your toolbar. After running your code, you should find your saved templates here.

Capture

The Code

This segment of the guide only shows snippets of code. You can download the full sample code from the Developer Community Code Share, here.

The sample code below creates a template from scratch, 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. Afterwards, you build your document package (transaction in the UI) with the applicable properties. Once your package is built, you call on your TemplateService to create your 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 Visibility.SENDER to your template, it means the template is only 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.

You can also create a template from an existing package. To do this, you will need the packageId of your package.

PackageId packageId = new PackageId("d9355f04-9bb2-4219-b9fa-734f2650a939");
PackageId templateFromPackage = eslClient.CreateTemplateFromPackage(packageId, "New Template From Package");

Running Your Code

After executing your code, you should be able to see your newly created template in your OneSpan Sign account.

Capture

Get the Code

Templates in the UI

To begin with, you should locate the templates section in your UI. After logging into your OneSpan Sign account, click on TEMPLATES in your toolbar. After running your code, you should find your saved templates here.

Capture

The Code

This segment of the guide only shows snippets of code. You can download the full sample code from the Developer Community Code Share, here.

Below is a sample JSON that you can include in your multi-part form POST request to create a new template from scratch. You can follow this guide for more detailed instructions on multi-part forms. The JSON request payload contains many empty properties that are not necessary for creating a new template. It is included in this guide to give you a list of options that are available and 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"; 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, take a look at the JSON Properties section below.

Response Payload

{
    "id": "9sKhW-h-qS9m6Ho3zRv3n2a-rkI="
}

If you set Visibility.SENDER to your template, it means the template is only 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.

Similarly, you can create a new template from an existing package (transaction in the UI). In this case, you will need the id of the package you are looking to clone:

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"
}

Running Your Code

After running your code, you should be able to see your newly created template in your OneSpan Sign account.

Capture

Get the Code

JSON Properties

Property Type Editable Required Default Sample Value(s)
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
email 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