kartik_shivhare

Sending Multiple Document using webclient in c# not working

0 votes
Hi Duo, I am not able to send the multiple pdf doc using webClient during creating Package with binary doc by the Rest Api, can you provide me the working code for the sending multiple doc for the multiple signers using webclient(For Rest Api).

Reply to: Sending Multiple Document using webclient in c# not working

0 votes

Hi Kartik, Have you tried the code in this thread?

  using (WebClient wc = new WebClient())
            {

                var URI = new Uri("https://sandbox.esignlive.com/api/packages");
                var MULTIPART_BOUNDARY = "----WebKitFormBoundary7MA4YWxkTrZu0gW";

                wc.Headers["Content-Type"] = "multipart/form-data; boundary=" + MULTIPART_BOUNDARY;
                wc.Headers["Accept"] = "application/json";
                wc.Headers["Authorization"] = "Basic your_API_Key";

                var postData = new StringBuilder();


                string jsonString = "......";

                postData.Append("--" + MULTIPART_BOUNDARY + "\r\n");
                postData.Append("Content-Disposition: form-data; name=\"file\"; filename=\"file1.pdf\"\r\n");
                postData.Append("Content-Type: application/pdf\r\n\r\n");


                postData.Append(System.Text.Encoding.Default.GetString(File.ReadAllBytes("your_file_path")));


                postData.Append("--" + MULTIPART_BOUNDARY + "\r\n");
                postData.Append("Content-Disposition: form-data; name=\"file\"; filename=\"file2.pdf\"\r\n");
                postData.Append("Content-Type: application/pdf\r\n\r\n");


                postData.Append(System.Text.Encoding.Default.GetString(File.ReadAllBytes("your_file_path")));

                postData.Append("\r\n\r\n");
                postData.Append("--" + MULTIPART_BOUNDARY + "\r\n");
                postData.Append("Content-Disposition: form-data; name=\"payload\"\r\n\r\n");
                postData.Append(jsonString);
                postData.Append("\r\n\r\n");
                postData.Append("--" + MULTIPART_BOUNDARY + "--");

                
                wc.UploadString(URI, "POST", postData.ToString());

This is the part that may interest you. Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Sending Multiple Document using webclient in c# not working

0 votes
Hi duo, I am doing the same thing but getting 400 bad request. Please find the attached text file as well as sample code below for the package Api request . this is working good for sending a single document. but getting error when sending multiple doc. using (WebClient wc = new WebClient()) { var URI = new Uri("https://sandbox.esignlive.com/api/packages"); var MULTIPART_BOUNDARY = "----WebKitFormBoundary7MA4YWxkTrZu0gW"; wc.Headers["Content-Type"] = "multipart/form-data; boundary=" + MULTIPART_BOUNDARY; wc.Headers["Accept"] = "application/json"; wc.Headers["Authorization"] = "Basic API_KEY"; var postData = new StringBuilder(); string jsonString = "{\n" + " \"documents\":[\n" + " {\n" + " \"approvals\":[\n" + " {\n" + " \"id\":\"Signature1\",\n" + " \"role\":\"Role1\",\n" + " \"fields\":[\n" + " {\n" + " \"page\":0,\n" + " \"top\":300,\n" + " \"subtype\":\"FULLNAME\",\n" + " \"optional\":true,\n" + " \"height\":50,\n" + " \"left\":100,\n" + " \"width\":200,\n" + " \"type\":\"SIGNATURE\",\n" + " \"name\":\"ExampleSignature\"\n" + " }\n" + " ],\n" + " \"name\":\"\"\n" + " }\n" + " ],\n" + " \"id\":\"document1\",\n" + " \"name\":\"ParallelPrograming\"\n" + " },\n" + " {\n" + " \"approvals\":[\n" + " {\n" + " \"id\":\"Signature2\",\n" + " \"role\":\"Role2\",\n" + " \"fields\":[\n" + " {\n" + " \"page\":0,\n" + " \"top\":300,\n" + " \"subtype\":\"FULLNAME\",\n" + " \"height\":50,\n" + " \"left\":100,\n" + " \"width\":200,\n" + " \"type\":\"SIGNATURE\",\n" + " \"name\":\"ExampleSignature\"\n" + " }\n" + " ],\n" + " \"name\":\"\"\n" + " }\n" + " ],\n" + " \"id\":\"document2\",\n" + " \"name\":\"ParallelPrograming - Copy\"\n" + " }\n" + " ],\n" + " \"status\":\"SENT\",\n" + " \"type\":\"PACKAGE\",\n" + " \"roles\":[\n" + " {\n" + " \"id\":\"Role1\",\n" + " \"type\":\"SENDER\",\n" + " \"signers\":[\n" + " {\n" + " \"id\":\"Signer1\",\n" + " \"email\":\"[email protected]\",\n" + " \"firstName\":\"rahul\",\n" + " \"lastName\":\"rathore\"\n" + " }\n" + " ],\n" + " \"name\":\"Role1\"\n" + " },\n" + " {\n" + " \"id\":\"Role2\",\n" + " \"type\":\"SIGNER\",\n" + " \"signers\":[\n" + " {\n" + " \"id\":\"Signer2\",\n" + " \"email\":\"[email protected]\",\n" + " \"firstName\":\"Crm\",\n" + " \"lastName\":\"Next\"\n" + " }\n" + " ],\n" + " \"name\":\"Role2\"\n" + " }\n" + " ],\n" + " \"name\":\"Example Package with multiple documents\"\n" + "}"; postData.Append("--" + MULTIPART_BOUNDARY + "\r\n"); postData.Append("Content-Disposition: form-data; name=\"file\"; filename=\"ParallelPrograming.pdf\"\r\n"); postData.Append("Content-Type: application/pdf\r\n\r\n"); postData.Append(System.Text.Encoding.Default.GetString(File.ReadAllBytes("C:/Users/rahulk/Downloads/ParallelPrograming.pdf"))); postData.Append("--" + MULTIPART_BOUNDARY + "\r\n"); postData.Append("Content-Disposition: form-data; name=\"file\"; filename=\"ParallelPrograming - Copy.pdf\"\r\n"); postData.Append("Content-Type: application/pdf\r\n\r\n"); postData.Append(System.Text.Encoding.Default.GetString(File.ReadAllBytes("C:/Users/rahulk/Downloads/ParallelPrograming - Copy.pdf"))); postData.Append("\r\n\r\n"); postData.Append("--" + MULTIPART_BOUNDARY + "\r\n"); postData.Append("Content-Disposition: form-data; name=\"payload\"\r\n\r\n"); postData.Append(jsonString); postData.Append("\r\n\r\n"); postData.Append("--" + MULTIPART_BOUNDARY + "--"); wc.UploadString(URI, "POST", postData.ToString());

Reply to: Sending Multiple Document using webclient in c# not working

0 votes
Hi kartik, With a quick test, the same JSON works fine at my side, can you also share the error message of 400 bad request? Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


Reply to: Sending Multiple Document using webclient in c# not working

0 votes
Hi Duo, I have attached the image file for your reference. and please provide the demo link or code sample for sending the zip file of multiple doc.

Attachments
Package.png104.25 KB

Reply to: Sending Multiple Document using webclient in c# not working

0 votes
Hi Kartik, Can you handle WebException in below way and receive the response stream OneSpan Sign returns to you (besides 400 status, OSS also returns error message)?
            catch (WebException webex)
            {
                WebResponse errResp = webex.Response;
                using (Stream respStream = errResp.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(respStream);
                    string text = reader.ReadToEnd();

                    Debug.WriteLine("error message: " + text);
                }
            }
Or more directly, can you use HTTP monitor tools like Fiddler to catch your HTTP outbound requests(fiddler is easy to use if you were developing with Windows)? It would be much easier to analyze reasons if we can see the raw HTTP request and the error message OneSpan Sign returns to you. Duo

Duo Liang OneSpan Evangelism and Partner Integrations Developer


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