chaudboy | Posts: 13

Can't successfully retrieve package id

0 votes
Hello, i'm a junior developer and it has been my second week learning Node JS so errors might be because of my poor use of Javascript. My problem is that after sending a request pretty much like in the example given on this link i get an undefined package id. I suppose this is caused by un unvalid json payload or options objet. Here is my code. The build of the json payload is done at line 23. I changed some of the values to make it look more like our webapp but since your example is quite basic i don't know if this is the problem .. The http request to your API is done at line 234. Thank you for your time.

Approved Answer
harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
You can build the payload as a string or an object. However, when making the request to esignlive, you'll have to send the payload as a string, as shown above.

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
Hi there, Looking at your JSON payload, can you remove the single quotation marks around where you put your own information? In other words, can you use the following payload and see if it resolves the issue?
{
  "roles": [
    {
      "id": "Signer1",
      "type": "SIGNER",
      "signers": [
        {
          "firstName": "lionel",
          "lastName": "jamaigne",
          "email": "[email protected]",
          "id": "Signer1"
        }
      ]
    },
    {
      "id": "Sender1",
      "type": "SIGNER",
      "signers": [
        {
          "firstName": "Haris",
          "lastName": "Haidary",
          "email": "[email protected]",
          "id": "Sender1"
        }
      ]
    }
  ],
  "documents": [
    {
      "fields": [
        {
          "value": "lionel",
          "name": "first_name"
        },
        {
          "value": "jamaigne",
          "name": "last_name"
        },
        {
          "value": "rue du truc",
          "name": "address"
        },
        {
          "value": "martelange",
          "name": "city"
        },
        {
          "value": "8832",
          "name": "zip"
        },
        {
          "value": "saipas",
          "name": "state"
        },
        {
          "value": "belgique",
          "name": "country"
        },
        {
          "value": "32499463127",
          "name": "phone_number"
        },
        {
          "value": "[email protected]",
          "name": "email"
        },
        {
          "value": "docunify sa",
          "name": "company"
        },
        {
          "value": "44",
          "name": "policy_number"
        }
      ],
      "name": "Sample Contract",
      "id": "contract",
      "extract": true
    }
  ],
  "name": "NodeJS Example",
  "type": "PACKAGE",
  "status": "DRAFT"
}
I was able to successfully create a package with the above payload. Also, make sure that you are using the same document I provided in my blog as the payload above is setup for the Document Extraction and Field Injection features.

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
Btw, here's the node.js code I used to create the package:
var fs = require("fs");
var request = require("request");

var options = { method: 'POST',
  url: 'https://sandbox.esignlive.com/api/packages',
  headers: 
   { 
     accept: 'application/json; esl-api-version=11.0',
     authorization: 'Basic api_key',
     'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
  formData: 
   { payload: '{"roles":[{"id":"Signer1","type":"SIGNER","signers":[{"firstName":"lionel","lastName":"jamaigne","email":"[email protected]","id":"Signer1"}]},{"id":"Sender1","type":"SIGNER","signers":[{"firstName":"Haris","lastName":"Haidary","email":"[email protected]","id":"Sender1"}]}],"documents":[{"fields":[{"value":"lionel","name":"first_name"},{"value":"jamaigne","name":"last_name"},{"value":"rue du truc","name":"address"},{"value":"martelange","name":"city"},{"value":"8832","name":"zip"},{"value":"saipas","name":"state"},{"value":"belgique","name":"country"},{"value":"32499463127","name":"phone_number"},{"value":"[email protected]","name":"email"},{"value":"docunify sa","name":"company"},{"value":"44","name":"policy_number"}],"name":"Sample Contract","id":"contract","extract":true}],"name":"NodeJS Example","type":"PACKAGE","status":"DRAFT"}',
     file: 
      { value: 'fs.createReadStream("C:/Users/hhaidary/Desktop/pdfs/doc1.pdf")',
        options: { filename: 'doc1.pdf', contentType: null } } } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
Hi, Thank you for such a fast answer. Do i have to send the payload as a string or as an object ? I don't understand why you have to use '+' to build the payload as a string if you cant use an object & just set the values with the form. Have a good afternoon.

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
Hello, Thank you for your help it was very helpful. Another error that i detected was my 'content-type' parameter which was set to 'null' instead of null. Unfortunately, i also have a problem with the session token. I embedded the token request in the handler of the package id request here in line 323. My session token is undefined & the body empty. Am i doing things correctly ? Again, thank you for your time.

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
Hey there, Is your package is SENT status? It is a requirement for retrieving a signer authentication token. In your json payload, change "status" to "SENT". I put it to draft simply because I didn't want to spam your email inbox :) Let me know.

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
Hi, Not only i still can't get the session token but now i don't get the package id either. Just by changing DRAFT to SENT they both are undefined. Are you sure these types of requests can be done with a sandbox account ? Have a good afternoon :)

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
Are you sure you are using the same document I provided? Like I mentioned in my previous post, the payload in my node.js example was setup to automatically extract the positions of the signatures from the pdf document. If you are using another document, then you will not be able to send the package for signing, as there won't be any signatures placed on the document. How about you try the following payload:
{
  "documents": [
    {
      "approvals": [
        {
          "id": "ExampleSignatureId",
          "role": "Signer1",
          "fields": [
            {
              "page": 0,
              "top": 200,
              "subtype": "LABEL",
              "height": 50,
              "binding": "{approval.signed}",
              "left": 100,
              "width": 200,
              "id": "myLabelField",
              "type": "INPUT",
              "value": "dd/mm/yyyy"
            },
            {
              "page": 0,
              "top": 100,
              "subtype": "FULLNAME",
              "height": 50,
              "left": 100,
              "width": 200,
              "type": "SIGNATURE",
              "name": "ExampleSignatureId"
            }
          ],
          "name": ""
        }
      ],
      "id": "sample-contract",
      "name": "Test Document"
    }
  ],
  "status": "SENT",
  "type": "PACKAGE",
  "roles": [
    {
      "id": "Signer1",
      "type": "SIGNER",
      "signers": [
        {
          "email": "[email protected]",
          "firstName": "John",
          "lastName": "Smith",
          "id": "Signer1"
        }
      ],
      "name": "Signer1"
    }
  ],
  "name": "Example Package"
}

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
Hello Mr Haidary, You are right i forgot about the fact that the code was set to this actual document. The retrieval of the packageid and the session token run smoothly thanks to your payload & advices. However, when i get the iframe in our front-end, i have this result as shown in the attachment. What can i understand from it ? Thank you++;

Attachments
chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
After noticing an error on the building of the url, i getanother error from your servers which is attached to this message.

Attachments
harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
What is the url you are embedding in the iframe?

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
Hello, I am using this URL: https://sandbox.esignlive.com/auth?authenticationToken='+token+'&target=https://sandbox.esignlive.com/a/transaction/'+packageid+'/designer'

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
I see. The URL you are trying to embed is for the designer, which requires a user authentication token and the package status being in draft. The designer is when you want to give your users access to the package and the freedom to place the signatures/fields on the documents. If you want to create a signing session, then you will need to embed the following URL using the signer authentication token: https://sandbox.esignlive.com/access?sessionToken={signerAuthenticationToken}

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
What we would like to do is to have a specific area for each users signing. What i'm doing now is provide an iframe based off the document they picked on our websites & then chose per signer a specific area. Will i be able to do this with your provided URL ?

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
Yes. Also, I would suggest using eSignLive's Document Extraction feature to place the signatures on your documents. It essentially automatically creates all signatures and fields that exist in an uploaded PDF file. The positions and sizes of the signatures and fields in the PDF file will be retained in eSignLive. Hence, depending what on documents your users choose, the signatures will automatically be placed once you create your package.

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
We would like to use the signature placement per signer in the actual designer, not doing it with some code. As i see the problem for me is that the result i get from the API call is just saying "Trasaction created successfully". But in fact what we would like to have is the PDF opened with some opportunities for us to, lets say, drag a user in a zone on the PDF and then send back the pdf so that the user can only sign in that area. It is not helpful for us to lock the postal code or first name or anything else. We would like to be able IN the designer in the iframe to only place the signature zone. Everything during the designer call. There are different informations in your websites and we don't know where to look anymore because there isn't a single URL that enables us to do this. I hope that you understand our concern about the designer. The state message doesn't respond to our needs.

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
As I mentioned in my previous post, then you will need to create a user authentication token instead of a signer authentication token and the package status must be in draft. Then you will be able to open a designer session using the URL you are trying to embed. https://developer.esignlive.com/guides/feature-guides/designer/#rest-api

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
Hello, I have a question about the signers: i would like to add them dynamically with a custom json that i add in the signers array in here. If i console.log the jsonpayload i can see the signers but in the designer i only see the first element. Last question, if leave the sgners array empty, in the recipients tab in the designer i can see the account i have in your developer website. Is it possible to disable this behaviour by default ? Thank you.

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
You can follow this guide on how to add signers to your package: https://developer.esignlive.com/guides/feature-guides/signer-management/#rest-api As for the second question, I'm not sure what you are referencing here. Would you mind taking a screenshot and showing me what you would like have turned off?

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
Can you send me the payload you are building so I can have a look at it? As for your second question, the account owner will have a "role" when creating packages. However, you can hide the account owner from the signers list in the designer by setting the visibility of the sender to false:
{
  "name": "Example Package",
  "data": {
    "senderVisible": false
  },
  "description": "",
  "emailMessage": "",
  "autocomplete": true,
  "settings": {
    "ceremony": {
      "inPerson": false
    }
  },
  "type": "PACKAGE",
  "due": null,
  "language": "en",
  "notarized": false
}

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
I just added your comment.
var jsonPayload = {
			"data": {
				"senderVisible": false
			},
			"language": "",
			"documents": [{
				"id": "sample-contract",
				"name": ""
			}],
			"status": "DRAFT",
			"type": "PACKAGE",
			"roles": [{
				"id": "Signer1",
				"type": "SIGNER",
				"signers": []
			}],
			"name": "Demande de signature(s)"
		}
Right now i have an empty array but i'd like to fill it will this kind of data
var new_signer = {
						"email": user.email,
						"firstName": user.firstname,
						"lastName": user.lastname,
						"id": "Signer1",
						"language": user.language
					};
and then do this. I can successfully add it in the array but since i cannot see any of it in the designer my guess is i should add it an other way.
jsonPayload.roles[0].signers.push(new_signer);

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
Can you try doing JSON.stringify(jsonPayload) before making your request?

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
I already do this as you suggested in a earlier post
var options = {
					method: 'POST',
					url: 'https://sandbox.esignlive.com/api/packages',
					// PROD: https://apps.esignlive.com/api
					headers: {
						accept: 'application/json; esl-api-version=11.0',
						authorization: 'Basic ' + api_key,
						'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
					},
					formData: {
						file: {
							value: document,
							options: {
								filename: fichier.filename,
								contentType: null
							}
						},
						payload: JSON.stringify(jsonPayload)
					}
				};

harishaidary | Posts: 1812

Reply to: Can't successfully retrieve package id

0 votes
Btw, here's how I am building my JSON to add multiple signers:
var jsonPayload = {
      "data": {
        "senderVisible": false
      },
      "language": "",
      "documents": [{
        "id": "sample-contract",
        "name": ""
      }],
      "status": "DRAFT",
      "type": "PACKAGE",
      "roles": [],
      "name": "Demande de signature(s)"
    };

  var new_signer1 = {
        "id": "Signer1",
        "type": "SIGNER",
        "signers": [
          {
            "email": "[email protected]",
            "firstName": "John",
            "lastName": "Smith",
            "id": "Signer1",
            "language": "en"
          }
        ]
          };
  
  var new_signer2 = {
        "id": "Signer2",
        "type": "SIGNER",
        "signers": [
          {
            "email": "[email protected]",
            "firstName": "Patty",
            "lastName": "Galant",
            "id": "Signer2",
            "language": "en"
          }
        ]
          };  

jsonPayload.roles.push(new_signer1);
jsonPayload.roles.push(new_signer2);

chaudboy | Posts: 13

Reply to: Can't successfully retrieve package id

0 votes
I see, maybe it was what i've been doing wrong,. I am adding signers not roles like you do ...

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