jose.castaneda

Create the package only with documents and update the package adding the signers later.

0 votes

I am trying to create the package only with documents and I will need to update it later adding the signers, the signature tag is already created in one of the documents, that is why I am using EnableExtraction. I get an error: 
 

Could not send the package. Exception: The remote server returned an error: (400) Bad Request. HTTP POST on URI https://sandbox.esignlive.com/api/packages/*********. Optional details: {"messageKey":"error.validation.sendPackage.noApprovals","message":"Cannot send package without approvals.","code":400,"name":"Validation Error"}

 

Code for the document creation:

                var client = new OssClient(apiKey, apiUrl);

                var stream = new MemoryStream(document);

                var packageName = Guid.NewGuid().ToString("n").Substring(0, 8);
                DocumentPackage package = PackageBuilder.NewPackageNamed(packageName)
                    .WithDocument(DocumentBuilder.NewDocumentNamed(documentId)
                    .FromStream(stream, DocumentType.PDF)
                    .EnableExtraction()
                )
                .Build();

                var packageId = client.CreatePackage(package);

 

Code for adding the signers:

                var client = new OssClient(apiKey, apiUrl);

                var packageId = new PackageId(packageString);

                var package = client.GetPackage(packageId);

                var existingSigners = package.Signers;
   
                var signatureParticipantFieldName = $"Sig_es_:signer1:signature";

                var email = "[email protected]";
                var firstName = "FirstName";
                var lastName = "LastName";

                if (!existingSigners.Any(x => x.Email == email))
                {
                    Signer signer = SignerBuilder.NewSignerWithEmail(email)
                    .WithFirstName(firstName)
                    .WithLastName(lastName)
                    .Build();
                    package.Signers.Add(signer);
                }

                var signature = SignatureBuilder.CaptureFor(email)
                    .WithName(signatureParticipantFieldName)
                    .WithPositionExtracted()
                    .Build();

                foreach (var document in package.Documents)
                {
                    document.Signatures.Add(signature);
                }
                
                client.UpdatePackage(packageId, package);

                client.SendPackage(packageId);



 


Reply to: Create the package only with documents and update the package adding the signers later.

0 votes

I was testing it with one of your examples but I get another error: OneSpanSign.Sdk.OssException: 'No Role found for signer email [email protected]'

 

            var client = new OssClient(apiKey, apiUrl);

            var packageId = new PackageId(packageString);
      
            //Add a signature
            var signature = SignatureBuilder.SignatureFor("[email protected]")
                      .OnPage(0)
                      .AtPosition(215, 510)
                      .WithSize(200, 50)
                      .WithId(new SignatureId("signature1"))
                      .Build();

            var createdPackage = client.GetPackage(packageId);

            var documentId = createdPackage.GetDocument("SignAndInitials_Example").Id;


            // Error here: OneSpanSign.Sdk.OssException: 'No Role found for signer email [email protected]'
            client.ApprovalService.AddApproval(createdPackage, documentId, signature);

            //Update a signature
            var updatedSignature = SignatureBuilder.CaptureFor("[email protected]")
                      .OnPage(0)
                      .AtPosition(215, 510)
                      .WithSize(300, 50)
                      .WithId(new SignatureId("signature1"))
                      .Build();

            var signatures = new List<Signature>();
            signatures.Add(updatedSignature);

            var updatedPackage = client.GetPackage(packageId);
            client.ApprovalService.UpdateApprovals(updatedPackage, documentId, signatures);

            //Delete a signature
            client.ApprovalService.DeleteApproval(packageId, documentId, "signature1");


Reply to: Create the package only with documents and update the package adding the signers later.

0 votes

Hi Jose,

 

Code wise, these places caused the issue:

(1)"client.UpdatePackage(packageId, package);" this call only updates package level attributes, for example due date, package description, but won't update signers and signature fields

(2)I see you are trying to leverage the position extraction feature, however OneSpan Sign document engine will only detect the PDF forms during its first upload - subsequent calls won't trigger the mapping.

 

If you can't determine the signer information, or even the signer numbers, you can add Placeholder recipients first then later update the placeholder with real signer information or remove the placeholder (fields binded to the placeholder will also be automatically deleted)

Use the sample code and PDF in Position Extraction guide for example:

            OssClient ossClient = new OssClient(API_KEY, API_URL);

            Placeholder placeholder = new Placeholder("Placeholder1");
            DocumentPackage superDuperPackage = PackageBuilder.NewPackageNamed("Sample Insurance policy")
                    .WithSigner(SignerBuilder.NewSignerPlaceholder(placeholder))
                    .WithDocument(DocumentBuilder.NewDocumentNamed("First Document")
                            .FromFile("your_file_path")
                            .EnableExtraction()
                            .WithSignature(SignatureBuilder.SignatureFor(placeholder)
                                    .WithName("sig1")
                                    .WithPositionExtracted()
                                    ))
                    .Build();

            PackageId packageId = ossClient.CreatePackage(superDuperPackage);
            Debug.WriteLine($"package id: {packageId.Id}");

            Signer signer = SignerBuilder.NewSignerWithEmail("[email protected]")
                .WithFirstName("John")
                .WithLastName("Smith")
                .WithCustomId(placeholder.Id)
                .Build();
            ossClient.PackageService.UpdateSigner(packageId, signer);

            //ossClient.PackageService.RemoveSigner(packageId, placeholder.Id);     //to remove optional placeholders

            ossClient.SendPackage(packageId);

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Attachments

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