bsohi

Create Package using templateid

0 votes

Hi,

I am trying to create a new package using .net sdk from template which is already defined in the UI. I am trying to find an example which will help me to get started. This is what we are trying to accomplish

1. Create package with templateid defined in UI portal

2. Set signer details like, Email, FirstName and LastName

3. Send value to the fields defined in the document.

If you can point me to the right direction that will be great.

Thanks

Balwinder


Approved Answer

Reply to: Create Package using templateid

0 votes

Hi Balwinder,

 

It's possible to select partial documents in the clone call (this is the API behind the scene POST /api/package/{templateId}/clone). However I don't think this functionality is exposed by .NET SDK. 

As a workaround, you can create the package first, then bulk delete the documents using this method:
PackageService.cs > public void DeleteDocuments (PackageId packageId, params string[] documentIds)

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Create Package using templateid

0 votes

Hi Balwinder,

 

Welcome to OneSpan Sign! Below .NET SDK code should be able to serve the purpose:


            OssClient ossClient = new OssClient(apiKey, apiUrl);

            String templateId = "5L77Cmq371EKUBfeLlAIUeN8LYc=";
            String placeholderId = "4d9580b6-9d49-4ded-b970-c911a08d3da7";
            String documentName = "Document1";
            var fieldValues = new Dictionary<string, string>
            {
                { "textfield1", "value1" },
                { "textfield2", "value2" }
            };


            //step1: create package from template
            DocumentPackage newPackage = PackageBuilder.NewPackageNamed("New Package Name")
                .DescribedAs("New Package Description")
                .WithEmailMessage("New Package Email Message")
                .WithSigner(SignerBuilder.NewSignerWithEmail("[email protected]")
                    .WithFirstName("john")
                    .WithLastName("smith")
                    .Replacing(new Placeholder(placeholderId))
                ).Build(); 
            
            
            var packageId = ossClient.CreatePackageFromTemplate(new PackageId(templateId), newPackage);
            Debug.WriteLine("packageId: " + packageId);


            //step2: update field value
            newPackage = ossClient.GetPackage(packageId);
            var doc = newPackage.GetDocument(documentName);

            foreach (var sig in doc.Signatures)
            {
                var updateSig = false;
                foreach (var field in sig.Fields)
                {
                    if (fieldValues.ContainsKey(field.Name))
                    {
                        updateSig = true;
                        field.Value = fieldValues[field.Name];
                    }
                }
                if (updateSig)
                {
                    ossClient.ApprovalService.ModifyApproval(newPackage, doc.Id, sig);
                }                                 
            }

 

Note that placeholderId is not the "Signer1" as you see in the UI label (Signer1 refers to the role name, however SDK doesn't expose role name). You can share the template ID and I can find the placeholder ID for you. Or if you want to find it yourself, log into your OSS UI portal first, then open a new tab and visit with this API URL:
GET /api/packages/{templateId}

It returns the template JSON and you can find the placeholderID under "roles" array > "id".

 

Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Create Package using templateid

0 votes

Hi Duo,

 

Thanks for quick response. On side note, is there any way to create package using template but specify document we need to send instead of all the documents configured in the template via UI.

 

Thanks


Reply to: Create Package using templateid

0 votes

Thanks.

Do you have documentIds exposed like TemplateId?

Or do we need to programatcially find it based on document name?

 

 


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