0

This is my C#.net code. When I create transient document id then I send document for signature then I receive it blank file. I think transient document id create for blank file. Could you help for it?

public getDocumentId getTransientDocumentId(string accessToken, string path1,string filename)
    {
        getDocumentId objGet = new getDocumentId();                   

        var nvc = new NameValueCollection
        {
            {"File", path1},
            {"Content-Type", "multipart/form-data"},
            {"Mime-Type", "application/pdf"},
            {"File-Name", filename}
        };

        string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
        byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
        byte[] boundarybytesF = System.Text.Encoding.ASCII.GetBytes("--" + boundary + "\r\n");  // the first time it itereates, you need to make sure it doesn't put too many new paragraphs down or it completely messes up poor webbrick.  

        HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("https://api.na1.echosign.com/api/rest/v5/transientDocuments");
        wr.Method = "POST";
        wr.Headers["Access-Token"] = string.Format(accessToken);
        wr.Headers["Authorization"] = string.Format("Bearer");
        wr.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17";
        wr.KeepAlive = true;
        wr.Credentials = System.Net.CredentialCache.DefaultCredentials;
        wr.AllowWriteStreamBuffering = true;

        wr.ContentType = "multipart/form-data; boundary=" + boundary;

        Stream rs = wr.GetRequestStream();


        bool firstLoop = true;
        string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
        foreach (string key in nvc.Keys)
        {
            if (firstLoop)
            {
                rs.Write(boundarybytesF, 0, boundarybytesF.Length);
                firstLoop = false;
            }
            else
            {
                rs.Write(boundarybytes, 0, boundarybytes.Length);
            }
            string formitem = string.Format(formdataTemplate, key, nvc[key]);
            byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
            rs.Write(formitembytes, 0, formitembytes.Length);
        }
        rs.Write(boundarybytes, 0, boundarybytes.Length);
        string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n";
        string header = string.Format(headerTemplate,  "File", new FileInfo(path1).Name, "application/octet-stream");
        byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
        rs.Write(headerbytes, 0, headerbytes.Length);
        FileStream fileStream = new FileStream(path1, FileMode.Open, FileAccess.Read);
        byte[] buffer = new byte[fileStream.Length];
        int bytesRead = 0;
        while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
        {
            rs.Write(buffer, 0, bytesRead);
        }
        fileStream.Close();
        byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
        rs.Write(trailer, 0, trailer.Length);
        rs.Close();
        try
        {
            var httpResponse = (HttpWebResponse)wr.GetResponse();
            using (var sr = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = sr.ReadToEnd();
                var jsonSerialization = new JavaScriptSerializer();
                var dictObj = jsonSerialization.Deserialize<Dictionary<string, dynamic>>(result);

                if (dictObj.Count > 0)
                {
                    objGet.transientDocumentId = Convert.ToString(dictObj["transientDocumentId"]);
                    objGet.success = "true";
                }
                else
                {
                    objGet.success = "false";
                }
            }     
        }
        catch (Exception ex)
        {
            objGet.success = "false: " + ex.Message.ToString();
        }
        return objGet;
    }
SurvivalMachine
  • 7,158
  • 13
  • 53
  • 74
  • Why don't you just post the relevant code, instead of adding all the extra commented lines which only makes your post harder to read? – Tavo Oct 03 '16 at 12:19

1 Answers1

0

For you purpose where you want to get the documents that you have attached to the agreement using transientDocument, you can get those documents using GET /agreements/{agreementId}/documents API call.

But as the question says "How to get transient documents". Well, there is no way you can get the transientDocument back using any API, reason being transientDocument is for temporary purpose generally used to create a single agreement and is short lived (just 7 days). If you want the uploaded document to be reused to create multiple agreements and can get its documents independently you should create libraryDocument instead using POST /libraryDocument

You can do GET API calls on those library documents to get there various details like documents, auditTrail etc. Here is the documentation link which you can follow to get more understanding on library documets

Palash Jain
  • 305
  • 1
  • 7