gui12343

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,

 


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 OneSpan Evangelism and Partner Integrations Developer


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

Duo Liang OneSpan Evangelism and Partner Integrations Developer


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