OneSpan Sign Developer: Upload Multiple Documents with REST
If you are developing your application with OneSpan Sign using REST, you have most probably encountered error messages when sending Post/Put requests. For troubleshooting purposes, I recommend using HTTP monitoring tools like Fiddler or Charles to capture the networking traffic going to OneSpan Sign. This will provide a better understanding of what is going on.
In this week’s blog, I will upload multiple documents to an existing transaction as an example to better explain what an HTTP request should look like, what to look for in Fiddler, and how to achieve this example using REST with C#.
Let’s get started!
What a Fiddler Trace Looks Like
Here’s a snapshot taken from Fiddler:
To better explore the issue, we will analyze this request using the following four points.
Uploading Documents Point 1:
If you are uploading documents to an existing package, you could use the below API URL and Request Header settings in your code or postman test:
HTTP Request
POST /api/packages/{packageId}/documents
HTTP Headers
Accept: text/html
Content-Type: multipart/form-data
Authorization: Basic api_key
Note that the “Accept” attribute should be set to “text/html” rather than “application/json”.
Uploading Documents Point 2:
From the screenshot, you can see each Content-Disposition is actually separated by a "--"+boundary.
If you are transferring your PDF into byte stream, your Content-type should be set to “application/pdf”, or you can set your Content-type to “text/plain” with plain text for a testing purpose.
There should be a newline before your document content.
If you need to upload multiple documents, the name of the Content-Disposition shares the same as “file”.
Uploading Documents Point 3:
The minimum payload for the document should include the “name” attribute as shown in the screenshot. However, it’s always recommended to add all approvals and attributes in your request JSON in one call rather than update your documents after uploading.
To upload multiple documents, your payload should be organized as such:
[
{
"name":"document1",
....
},
{
"name":"document2",
....
}
]
Uploading Documents Point 4:
At the end, you need to use "--"+boundary+"--" to complete the request. Specially, there are two extra bashes in the end.
Uploading Multiple Documents
Above is a C# sample function to upload multiple documents. By reading the code, you can see how the Web Request is transformed from code and create your own function within your development programming language, depending on your own business logic. For the full code, you can refer to this thread. If you have questions regarding this blog or anything else concerning integrating OneSpan Sign into your application, visit the Developer Community Forums.