chris.mah | Posts: 4

Removing role programmatically from template results in "Cannot send package without approvals"

0 votes

Hi,

Currently using APEX SDK to retrieve a template from OneSpanSign, then removing roles from the template as needed, if the number of signers change. I've currently defined 2 roles on the template, and am trying the scenario where only 1 is needed. 

In Apex, I am retrieving the package template, then updating it such that it only includes 1 role and 1 approval. Upon creating the new package, I get this validation error- Error creating OneSpan package: 400 - Bad Request - {"messageKey":"error.validation.sendPackage.noApprovals","message":"Cannot send package without approvals.","code":400,"name":"Validation Error"}

Any idea as to what I'm missing? The createPackage seems to be expecting an Approval for the 2nd role when I've removed that as well.

{
  "status": "SENT",
  "roles": [
    {
      "type": "SIGNER",
      "signers": [
        {
          "name": "wa first wa last",
          "lastName": "wa last",
          "firstName": "wa first",
          "email": "[email protected]"
        }
      ],
      "reassign": false,
      "name": "admin1",
      "locked": false,
      "index": 1,
      "id": "33ed690d-32e3-4130-91d8-b7c7529faed6",
      "emailMessage": {
        "content": ""
      },
      "attachmentRequirements": []
    }
  ],
  "name": "Form 2021-05-11, 8:25 a.m.",
  "emailMessage": "This is an email message.",
  "documents": [
    {
      "size": 82041,
      "pages": [
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 0,
          "id": "",
          "height": 1030
        },
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 1,
          "id": "",
          "height": 1030
        }
      ],
      "name": "Electronic Disclosures and Signatures Consent",
      "index": 0,
      "id": "default-consent",
      "fields": [],
      "extract": false,
      "description": "Must be accepted and agreed to before starting the signing process.",
      "data": {
        "ese_document_texttag_extract_needed": "false"
      },
      "approvals": []
    },
    {
      "size": 477335,
      "pages": [
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 0,
          "id": "",
          "height": 1030
        },
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 1,
          "id": "",
          "height": 1030
        },
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 2,
          "id": "",
          "height": 1030
        },
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 3,
          "id": "",
          "height": 1030
        },
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 4,
          "id": "",
          "height": 1030
        },
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 5,
          "id": "",
          "height": 1030
        },
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 6,
          "id": "",
          "height": 1030
        },
        {
          "width": 796,
          "version": 0,
          "top": 0,
          "left": 0,
          "index": 7,
          "id": "",
          "height": 1030
        }
      ],
      "name": "Form",
      "index": 1,
      "id": "2771320150334f0a48822713678e9be4a892fe0f9708a725",
      "fields": [],
      "extract": false,
      "description": "",
      "data": {
        "ese_document_texttag_extract_needed": "false"
      },
      "approvals": [
        {
          "role": "33ed690d-32e3-4130-91d8-b7c7529faed6",
          "name": "admin_sign",
          "id": "XEqiiRseIZkC",
          "fields": [
            {
              "width": 164,
              "validation": {
                "required": false,
                "pattern": "",
                "errorMessage": ""
              },
              "type": "INPUT",
              "top": 681,
              "subtype": "TEXTFIELD",
              "page": 6,
              "name": "email1",
              "left": 151,
              "id": "cnMqJMdIzuIU",
              "height": 13,
              "extract": false
            },
            {
              "width": 164,
              "validation": {
                "required": false,
                "pattern": "",
                "errorMessage": ""
              },
              "type": "INPUT",
              "top": 663,
              "subtype": "TEXTFIELD",
              "page": 6,
              "name": "name1",
              "left": 153,
              "id": "PQjDK0ZC470P",
              "height": 13,
              "extract": false
            },
            {
              "width": 192,
              "value": "",
              "type": "SIGNATURE",
              "top": 622,
              "subtype": "FULLNAME",
              "page": 6,
              "name": "admin_sign",
              "left": 151,
              "id": "v857AI9L6iQ9",
              "height": 34,
              "extract": false
            }
          ]
        }
      ]
    }
  ],
  "description": "This is a package created from template.",
  "data": {
    "sdk": "Apex v1.0",
    "origin": "Salesforce"
  }
}

 

 


Duo_Liang | Posts: 3776

Reply to: Removing role programmatically from template results in "Cannot send package without approvals"

0 votes

Hi chris.mah,

 

Thanks for your post! As per your description, try below code and follow the three steps to #1 create a package out of a template #2 remove the second placeholder/signer #3 send the package.

 

              //step1: create package out of a template
              OneSpanAPIObjects.Package_x pkg = new OneSpanAPIObjects.Package_x();   
              //Set basic package info   
              pkg.name = 'Create Package From Template - ' + Datetime.now().format();   
              pkg.description = 'This is a package created from template.';   
              pkg.emailMessage = 'This is an email message.';   
              //Build actual Role in replacement of placeholder   
              String placeholder1Id = 'placeholder1';   
              OneSpanAPIObjects.Role role1 = new OneSpanAPIObjects.Role();   
              OneSpanAPIObjects.Signer signer1 = new OneSpanAPIObjects.Signer();   
              signer1.firstName = 'signer1_firstname';   
              signer1.lastName = 'signer1_lastname';   
              signer1.email = '[email protected]';   
              signer1.id = placeholder1Id;   
              role1.signers = new List<OneSpanAPIObjects.Signer>{signer1};   
              role1.id = placeholder1Id;   
              pkg.roles = new List<OneSpanAPIObjects.Role>{role1};   
              pkg = sdk.helper.createPackageFromTemplate(pkg, 'E-_tmDsICwCkM2vqFuzVxF7NVQQ=');   
              System.debug('Package id: ' + pkg.id); 
            
              //step2: remove placeholder 2 / signer 2
              sdk.helper.deleteRole(pkg.id, 'placeholder2'); 
            
              //step3: send package
              OneSpanAPIObjects.Package_x pkg2 = new OneSpanAPIObjects.Package_x();   
              pkg2.status = OneSpanAPIObjects.PackageStatus.SENT;
              sdk.updatePackage(pkg2, pkg.id);  

 

I've highlighted three places where you'd replace with your actual role IDs and template ID.

 

Duo


chris.mah | Posts: 4

Reply to:

0 votes

Thanks for the quick response Duo!

The above makes sense and I've tried your recommendation in both my current implementation as well as separately (just the code above) and receive this error in both scenarios- OneSpanRESTAPIHelper.OneSpanRestAPIHelperException: Error deleting Role with OneSpan: 303 - See Other - 

Any idea?


Duo_Liang | Posts: 3776

Reply to:

0 votes

Hi Chris,

 

I've changed the code a little bit - however it shouldn't be related to your error.

               OneSpanSDK sdk = new OneSpanSDK();


              //step1: create package out of a template
              OneSpanAPIObjects.Package_x pkg = new OneSpanAPIObjects.Package_x();   
              //Set basic package info   
              pkg.name = 'Create Package From Template - ' + Datetime.now().format();   
              pkg.description = 'This is a package created from template.';   
              pkg.emailMessage = 'This is an email message.';   
              //Build actual Role in replacement of placeholder   
              String placeholder1Id = '0315081d-ed86-4ba9-8421-5608c32dca01';   
              OneSpanAPIObjects.Role role1 = new OneSpanAPIObjects.Role();   
              OneSpanAPIObjects.Signer signer1 = new OneSpanAPIObjects.Signer();   
              signer1.firstName = 'signer1_firstname';   
              signer1.lastName = 'signer1_lastname';   
              signer1.email = '[email protected]';   
              signer1.id = placeholder1Id;   
              role1.signers = new List<OneSpanAPIObjects.Signer>{signer1};   
              role1.id = placeholder1Id;   
              pkg.roles = new List<OneSpanAPIObjects.Role>{role1};   
              OneSpanAPIObjects.Package_x pkg2 = sdk.helper.createPackageFromTemplate(pkg, 'GMAMTy9HR6IaiV6ZJ-zVu1sYDPk=');   
              System.debug('Package id: ' + pkg2.id); 
            
              //step2: remove placeholder 2 / signer 2
              sdk.helper.deleteRole(pkg2.id, '62a6e645-7968-4d8b-ad51-f0df9a743403'); 
            
              //step3: send package
              pkg.status = OneSpanAPIObjects.PackageStatus.SENT;
              sdk.updatePackage(pkgpkg2.id); 

 

For your specific error, have you passed in the actual role ID into deleteRole() function? Could you share the template ID to me?

 

Duo 


chris.mah | Posts: 4

Reply to: Removing role programmatically from template results in "Cannot send package without approvals"

0 votes

Hey Duo,

 

Yup- I'm passing in the 2 role IDs and the template Id.

 

Template Id = wZMPfnzmuJUNFqX3HvV6wCTDhNg=

placeholder1Id= 33ed690d-32e3-4130-91d8-b7c7529faed6

role2 Id (to be deleted) - c67d0e16-b03b-4389-aed8-c0eef1eda4a9

 

Thanks,

Chris


Duo_Liang | Posts: 3776

Reply to:

0 votes

Hi Chris,

 

Thanks for the sharing! The template looks straightforward, and after reproducing the same template to my account, I can successfully execute below code snippet without hitting the 303 error:
              OneSpanSDK sdk = new OneSpanSDK();

              //step1: create package out of a template
              OneSpanAPIObjects.Package_x pkg = new OneSpanAPIObjects.Package_x();   
              //Set basic package info   
              pkg.name = 'Create Package From Template - ' + Datetime.now().format();   
              pkg.description = 'This is a package created from template.';   
              pkg.emailMessage = 'This is an email message.';   
              //Build actual Role in replacement of placeholder   
              String placeholder1Id = '33ed690d-32e3-4130-91d8-b7c7529faed6';   
              OneSpanAPIObjects.Role role1 = new OneSpanAPIObjects.Role();   
              OneSpanAPIObjects.Signer signer1 = new OneSpanAPIObjects.Signer();   
              signer1.firstName = 'signer1_firstname';   
              signer1.lastName = 'signer1_lastname';   
              signer1.email = '[email protected]';   
              signer1.id = placeholder1Id;   
              role1.signers = new List<OneSpanAPIObjects.Signer>{signer1};   
              role1.id = placeholder1Id;   
              pkg.roles = new List<OneSpanAPIObjects.Role>{role1};   
              OneSpanAPIObjects.Package_x pkg2 = sdk.helper.createPackageFromTemplate(pkg, 'rSyDhKhyz6s97HYPv-I1_GZgKJk=');   
              System.debug('Package id: ' + pkg2.id); 
            
              //step2: remove placeholder 2 / signer 2
              sdk.helper.deleteRole(pkg2.id, 'c67d0e16-b03b-4389-aed8-c0eef1eda4a9'); 
            
              //step3: send package
              pkg.status = OneSpanAPIObjects.PackageStatus.SENT;
              sdk.updatePackage(pkg, pkg2.id); 

 

Duo


Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off