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 Request Payload 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": "[email protected]"
  },
  "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

Request Payload

PropertyTypeEditableRequiredDefaultSample Value(s)
statusstringYesNoDRAFTDRAFT / SENT / COMPLETED / ARCHIVED / DECLINED / OPTED_OUT / EXPIRED
autoCompletebooleanYesNotruetrue / false
typestringYesNoPACKAGEPACKAGE / TEMPLATE / LAYOUT
namestringYesYesn/aDocument Attributes Example
trashedbooleanYesNofalsetrue / false
visibilitystringYesNoACCOUNTACCOUNT / SENDER
emailMessagestringYesNon/aPlease sign at the earliest convenience.
descriptionstringYesNon/aThis template has been created from scratch
documents
namestringYesNon/asample doc
approvals
fields
subtypestringYesNon/aFULLNAME / INITIALS / CAPTURE / MOBILE_CAPTURE / LABEL / TEXTFIELD / TEXTAREA / CHECKBOX / DATE / RADIO / LIST
typestringYesNon/aSIGNATURE / INPUT
bindingstringYesNonull{approval.signed} / {signer.title} / {signer.name} / {signer.company}
extractbooleanYesNofalsetrue / false
heightintegerYesNo5050 / 100 / 150 ...
leftintegerYesNo050 / 100 / 150 ...
pageintegerYesNo00 / 1 / 2 ...
topintegerYesNo050 / 100 / 150 ...
widthintegerYesNo20050 / 100 / 150 ...
rolestringYesNon/aClient1
roles
idstringYesNon/aClient1
namestringYesNon/aClient1
typestringYesNoSIGNERSIGNER / SENDER
signers
emailstringYesYesn/a[email protected]
firstNamestringYesYesn/aJohn
lastNamestringYesYesn/aSmith
phonestringYesNon/a514-555-8888
idstringYesNon/aClient1
companystringYesNon/aAcme Inc.
titlestringYesNon/aManaging Director

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 one signer.
    	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 = placeholderId;
    	sdk.helper.createRole(packageId, placeholder1);		//create role to template
    	
    	
    	//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);		//upload document to template
    	
    	//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);	//add approval and fields to template
You can also create a template from an existing package. For this, you will need the package ID of your package. 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);
Note: Create package from template and create template from package share the same function.

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