gui12343 | Posts: 12

Create a package from a template with Node js

0 votes

Hello,

I have encountered a problem when I tried to create a package from a template with the rest API. I used all tips and instruction I found in the documentation and on forums, but I did'nt found a solution yet. Here is one of the documentation : https://community.onespan.com/documentation/onespan-sign/guides/feature-guides/developer/creating-transaction-template.

When I try it, I get this error : "Unsuported media type". If I try to change the format of the json, or use different request format, I get some errors like "Failed to deserialize json string to target type com.silanis.esl.api.model.Package"

Here is my code in nodeJs, so you can better understand what I am trying to do :

-----------------------------------------------------------------------------------------------------------

var options_send = { method: 'POST',

        url: 'https://apps.e-signlive.ca/api/packages/{myTemplateId}/clone', 

        headers: 

        { 

            'Accept': 'application/json; esl-api-version=11.35',

            'authorization': 'Basic ' + this.api_key,

            'Content-Type':'application/json'},

           formData:{payload:`{

          "name":"Package created from template through REST API",

          "description":"Package created with the OneSpan Sign REST API",

          "emailMessage":"This message should be delivered to all signers",

          "autocomplete":true,

          "type":"PACKAGE",

          "language":"fr",

          "status" : "SENT",

          "roles": [

            {

              "id": "Signer1",

              "type": "SIGNER",

              "signers": [

                {

                  "id": "Signer1",

                  "firstName": "myfirstName",

                  "lastName": "myLastName",

                  "email": "[email protected]"

                }

              ],

              "name": "Signer1"

            }

          ]

        }`}, json:true

          

   }

 

        request(options_send, callback2);

-----------------------------------------------------------------------------------------------------------

 

Note that when I replace the argument "formData" by "body", the package is created, but without any informations about the signer in it, so it can't be send and it goes into the "DRAFT" section in my OneSpan account. Let me know if you see what I am doing wrong here!

 

Thank you very much,

 


Duo_Liang | Posts: 3776

Reply to: Create a package from a template with Node js

1 votes

Hi gui12343,

 

Thanks for reaching out to us! Two points regarding to your questions:

(1)As per this StackOverflow post as well as my own test, you should put JSON as "body" of the options.

var options = { uri: 'https://myurl.com', method: 'POST', json: true, body: {'my_date' : 'json'} } request(options, myCallback)

Otherwise if you put it as "formData" or "form", OneSpan Sign system would thought the request type is multipart/form-data, therefore threw the "Unsuported media type" error.

(2)The reason why "the package is created, but without any informations about the signer in it" is because the role ID of the placeholder may not be "Signer1" as you thought, in which case if the role ID is a mismatch, OneSpan Sign system will add a new role instead of replacing the placeholder.

If you created the template from UI portal, the "Signer1" only specifies the role name, whole the actual role ID is uniquely generated by system in format of UUID. If you provide me your template ID, I can check the actual role ID for you.

{
  "name": "Package created from template through REST API",
  ......
  "roles": [
    {
      "id": "0be4ccd5-bf89-4bed-9dc1-c47cea76ffeb",
      "type": "SIGNER",
      "signers": [
        {
          "firstName": "myfirstName",
          "lastName": "myLastName",
          "email": "[email protected]"
        }
      ]
    }
  ]
}

 

Duo


Duo_Liang | Posts: 3776

Reply to: Create a package from a template with Node js

0 votes

Thanks for the sharing! The actual role ID is "9ad1728d-2e24-44cd-9f74-0fc534dedd7f"

 

Duo


gui12343 | Posts: 12

Reply to:

0 votes

Hi again!

I still have a problem when I try to send a form with my code... We changed the templates that we send and now I have this error : error.validation.packageActivation.unassignedRole. 

Here are the 2 templates id we use : 

templateIdFr:'f3Y8GI9_KpKaakpR1TdCh6pj40Q=', 

templateIdEn:'HL9zxrDwwPo1AFMyI3UNrg3dzFI=',

 

Could you help me with that? Maybe we did'nt set up our templates like the last one I guess and I am not able to find the right signer id..

Thank you very much for your help.


Duo_Liang | Posts: 3776

Reply to: Create a package from a template with Node js

0 votes

Hi gui12343,

 

This error message "error.validation.packageActivation.unassignedRole" normally indicates that there is a role with no signer (placeholder recipient), so I am guessing your code didn't correctly specify the placeholder role ID like the other time? Could you kindly check if you've specified the placeholder IDs as:

f3Y8GI9_KpKaakpR1TdCh6pj40Q=: 939dbaa2-99b7-4425-beb0-51b058df69ca

HL9zxrDwwPo1AFMyI3UNrg3dzFI=: 5776a676-eba7-42ed-a285-859f28ca763c

 

Duo


Ronald114 | Posts: 1

Reply to: Create a package from a template with Node js

0 votes

First things first, gather your project templates together. If you haven’t got any templates, it’s time to make one. I started with a simple NPM project with a spec/index.spec.js file, an index.js file, a package.json, and a .gitignore. I filled these files with generic starter code.

 

 

FaceTime PC
 

gui12343 | Posts: 12

Reply to: Create a package from a template with Node js

0 votes

Hi Duo_Liang, 

 

Thank you, it worked! I found out how to retrieve the information now, I should be able to do it myself next time with postman haha. 

I have an other question, I don't know if I need to open a new post, but I will ask it here ; Do you know if we can do fields injection in the payload of a clone template request? I read that it was not possible in the past, maybe it is now. 

 

Thank you again,

 

- Gui


Duo_Liang | Posts: 3776

Reply to:

0 votes

Hi Gui,

 

Unfortunately it's still not available in the current implementation, while you can use label fields instead, which display the value and are not editable during signing ceremony. After your application clones a package out of the template, bulk update the fields using this API (you can invoke a GET call prior to the PUT call and inject the field values by filtering field names)

 

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