Attaching .docx file to Package

0 votes

I 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?

Approved Answer

Reply to: Attaching .docx file to Package

1 votes

Hi 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 Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Attaching .docx file to Package

1 votes

Hi 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



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