ApplyLayouts fails to apply layout to package document
Thursday, September 17, 2020 at 09:53amHello,
I have created the following draft package:
DocumentPackage draftDocumentPackage = PackageBuilder
.NewPackageNamed(Path.GetFileNameWithoutExtension(pdfFile))
.WithSigner(SignerBuilder
.NewSignerWithEmail(drow["_EmailAddress"])
.WithFirstName(drow["_FirstName"])
.WithLastName(drow["_LastName"]))
.WithDocument(DocumentBuilder
.NewDocumentNamed(Path.GetFileNameWithoutExtension(pdfFile))
.WithId(drow["DocId"])
.WithDescription("Document with applied layout description.")
.FromFile(pdfFile))
.Build();
PackageId draftPackageId = OneSpanClient.CreatePackage(draftDocumentPackage);
The layout is previously and manually created in eSign, so I retrieve the layout:
int i = 1;
int maxNumberOfLayouts = 5;
EslClient OneSpanClient = new EslClient(OLEAPIKEY, OLEURL);
// The first step is to retrieve the layouts from the first page.
// N number of layouts are retrieved at a time but this can be set to any number and could be configurable if necessary
IList<DocumentPackage> layouts = OneSpanClient.LayoutService.GetLayouts(Direction.DESCENDING, new PageRequest(i, maxNumberOfLayouts));
IList<DocumentPackage> layoutList = new List<DocumentPackage>();
int count = layouts.Count;
if (count == 0) LogFile.Write(3, "There are NO layouts to retrieve from the OneSpan eSign!");
while (count != 0) {
foreach (DocumentPackage layout in layouts) {
// This is where the layout name and id is retrieved.
// Check app.config for layout name
if (layout.Name.ToUpper() == appConfig.LayoutName.ToUpper()) {
layoutList.Add(layout);
i++;
}
}
// Finally, retrieve the next N number of layouts from the second page and start over up until you’ve retrieved all your layouts.
layouts = OneSpanClient.LayoutService.GetLayouts(Direction.DESCENDING, new PageRequest(i, maxNumberOfLayouts));
count = layouts.Count;
}
Then I apply the layout to the package:
EslClient OneSpanClient = new EslClient(OLEAPIKEY, OLEURL);
bool LayoutApplied = false;
//apply layout to one or more packages
foreach (PackageId packageId in draftPackageList) {
foreach (DocumentPackage layout in layoutList) {
var layoutId = layout.Id.ToString();
var layoutName = layout.Name;
IList<Document> documentList = layout.Documents;
foreach (Document document in documentList) {
var documentId = document.Id;
if (layoutName.Contains(document.Name)) {
try {
OneSpanClient.LayoutService.ApplyLayout(packageId, documentId, layoutId);
LayoutApplied = true;
}
catch (Exception ex) {
LogFile.Write(1, $"{ex.GetType().ToString()} while in {MethodBase.GetCurrentMethod().Name}. (" + ex.ToString() + ")");
}
}
}
}
}
return LayoutApplied;
I keep getting this Exception:
10:49:21.665: Silanis.ESL.SDK.EslServerException while in ApplyLayouts. (Silanis.ESL.SDK.EslServerException: Could not apply layout. Exception: The remote server returned an error: (404) Not Found.
HTTP POST on URI https://sandbox.esignlive.com/api/packages/oOXqHr10kw2vYIJExcdOZCignZQ=/documents/8f18c94ecc4eb5ff90a4b74324e514df207b1d6d4cda057f/layout?layoutId=ePiIFQtKCoE04Tmmu6YztAmdTSs=.
Optional details: {"messageKey":"error.validation.packageManagement.invalidDocument","technical":"Document: 8f18c94ecc4eb5ff90a4b74324e514df207b1d6d4cda057f was not found","message":"Can not find specified document.","code":404,"name":"Resource Not Found"} ---> Silanis.ESL.SDK.EslServerException: The remote server returned an error: (404) Not Found. HTTP POST on URI https://sandbox.esignlive.com/api/packages/oOXqHr10kw2vYIJExcdOZCignZQ=/documents/8f18c94ecc4eb5ff90a4b74324e514df207b1d6d4cda057f/layout?layoutId=ePiIFQtKCoE04Tmmu6YztAmdTSs=. Optional details: {"messageKey":"error.validation.packageManagement.invalidDocument","technical":"Document: 8f18c94ecc4eb5ff90a4b74324e514df207b1d6d4cda057f was not found","message":"Can not find specified document.","code":404,"name":"Resource Not Found"} ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at Silanis.ESL.SDK.Internal.HttpMethods.PostHttp(String apiToken, String path, Byte[] content)
--- End of inner exception stack trace ---
at Silanis.ESL.SDK.Internal.HttpMethods.PostHttp(String apiToken, String path, Byte[] content)
at Silanis.ESL.SDK.RestClient.Post(String path, String jsonPayload)
at Silanis.ESL.SDK.LayoutApiClient.ApplyLayout(String packageId, String documentId, String layoutId)
--- End of inner exception stack trace ---
at Silanis.ESL.SDK.LayoutApiClient.ApplyLayout(String packageId, String documentId, String layoutId)
at Silanis.ESL.SDK.LayoutService.ApplyLayout(PackageId packageId, String documentId, String layoutId)
at IdentifiFormToPDF.Program.ApplyLayouts(IList`1 draftPackageList, IList`1 layoutList) in C:\Solutions\Client Shared\Non-Core Specific\IdentifiFormToPDF\IdentifiFormToPDF\Program.cs:line 811)
Why can't eSign find the layout to apply to the package?
Reply to: ApplyLayouts fails to apply layout to package document
Thursday, September 17, 2020 at 10:06amNever mind.
I have found the error and corrected it.
eSign now applies the layout correctly and sends it to the signer correctly.
Once I used the supplied DocID when the draftPackage was created INSTEAD of the actual DocumentPackage documents id, everything worked as expected. DOH!!!!
Thanks for you help!
This forum request is closed by customer :)
Reply to: ApplyLayouts fails to apply layout to package document
Thursday, September 17, 2020 at 10:20amHi Clayton,
For function "OneSpanClient.LayoutService.ApplyLayout(packageId, documentId, layoutId);", the second parameter document ID should come from the DRAFT package (where you specified as " .WithId(drow["DocId"])"), not from the layout.
Duo
Reply to: ApplyLayouts fails to apply layout to package document
Thursday, September 17, 2020 at 10:23amGlad you figured it out! Feel free to post if you have any other questions!
Duo