Attaching .docx file to Package
Saturday, May 13, 2023 at 07:04pmI am working on a solution to create a package containing a single document.
When I use a .pdf file, this works fine - the document is sent; a signing URL is generated and I can sign.
When I try to use a .docx file, I get a HTTP 400.
00:57:39:914 EXCEPTION_THROWN [147]|OneSpanRESTAPIHelper.OneSpanRestAPIHelperException: Error creating OneSpan package with documents: 400 - Bad Request - {"messageKey":"error.validation.invalidParameters","technical":"Unexpected Content-Disposition value for parameter 'name'","message":"Invalid parameters.","code":400,"name":"Validation Error"}
This works absolutely fine for PDF, so I know the code for generating the package is fine - just can't find anything online to support.
Unfortunately transferring to Any ideas?
Reply to: Attaching .docx file to Package
Monday, May 15, 2023 at 08:41amHi kdyer,
Thanks for your post! I did a quick test creating a transaction via APEX sdk with a docx file, and it seems succeeded with the APEX sdk without modification. I attached the raw request body fetched from HTTP traffic tool where you'll see although the form-data content type says application/pdf, OneSpan Sign API still accepts this request.
Below is the APEX code I used to create transaction where I read the docx file from a static resource:
OneSpanSDK sdk = new OneSpanSDK();
OneSpanAPIObjects.Package_x pkg = new OneSpanAPIObjects.Package_x();
pkg.name = 'Test Postiion Extraction - ' + Datetime.now().format();
pkg.status = OneSpanAPIObjects.PackageStatus.SENT;
//Prepare Documents Blob
String document1Name = 'Document1';
StaticResource sr = [SELECT Id, Body FROM StaticResource WHERE Name = 'test_position_extraction' LIMIT 1];
Map<String,Blob> documentBlobMap = new Map<String,Blob>();
documentBlobMap.put(document1Name, sr.Body);
//Create Document Metadata
OneSpanAPIObjects.Document document1 = new OneSpanAPIObjects.Document();
document1.name = document1Name;
document1.id = document1Name;
document1.extract = true; //document level extraction:true
pkg.documents = new List<OneSpanAPIObjects.Document>{document1};
......
//Send package One Step
String packageId = sdk.createPackage(pkg,documentBlobMap);
System.debug('PackageId: ' + packageId);
Back to the issue itself, I think it's worth check in below asepcts:
(1)Try to upload a different docx file
(2)I believe there are at least two SDK methods to upload a document:
sdk.createDocuments(packageId, document, doc);
or the method I used above sdk.createPackage(pkg,documentBlobMap);
You can try with anther method to see if it makes any difference
(3)Try to fetch the raw request body.
Duo
Reply to: Attaching .docx file to Package
Tuesday, May 16, 2023 at 03:35pmHi Duo,
Thanks for the support.
It appears that the createDocuments method on the SDK is the problem, it references the encodeDocuments method which has the document Content-Type hardcoded as application/pdf.
I've switched over to your suggested method
Cheers