This topic contains 5 replies, has 2 voices, and was last updated by  Duo_Liang 2 months, 1 week ago.

  • Author
    Posts
  • Participant
    kartik_shivhare
    Member
    Member since: 20.02.2018
    Number of posts: 21

    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).

    Keymaster
    Duo_Liang
    Guru
    Member since: 14.06.2018
    Number of posts: 766

    Score

    0

    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 Junior Technical Evangelist
    Participant
    kartik_shivhare
    Member
    Member since: 20.02.2018
    Number of posts: 21

    Score

    0

    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\”:\”signer1@example.com\”,\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\”:\”signer2@example.com\”,\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());

    • This reply was modified 2 months, 2 weeks ago by  Duo_Liang.
    Keymaster
    Duo_Liang
    Guru
    Member since: 14.06.2018
    Number of posts: 766

    Score

    0

    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 Junior Technical Evangelist
    • This reply was modified 2 months, 2 weeks ago by  Duo_Liang.
    • This reply was modified 2 months, 2 weeks ago by  Duo_Liang.
    • This reply was modified 2 months, 2 weeks ago by  Duo_Liang.
    • This reply was modified 2 months, 1 week ago by  Duo_Liang.
    Participant
    kartik_shivhare
    Member
    Member since: 20.02.2018
    Number of posts: 21

    Score

    0

    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:
    You must be logged in to view attached files.
    Keymaster
    Duo_Liang
    Guru
    Member since: 14.06.2018
    Number of posts: 766

    Score

    0

    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 Junior Technical Evangelist

You must be logged in to reply to this topic.