如何获得瞬态文档id使用adobe echosign api

本文关键字:使用 adobe echosign api id 文档 何获得 | 更新日期: 2023-09-27 18:11:26

这是我的c# .net代码。当我创建临时文档id,然后我发送文档签名,然后我收到它的空白文件。我认为临时文件是为空白文件创建的。你能帮忙吗?

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;
    }

如何获得瞬态文档id使用adobe echosign api

对于您想要使用transientDocument获取已附加到协议的文档的目的,您可以使用get/agreements/{agreementId}/documents API调用获取这些文档。

但正如问题所说的"如何获得临时文件"。好吧,你无法使用任何API获得transientDocument,原因是transientDocument是临时目的,通常用于创建单个协议,并且是短暂的(只有7天)。如果你希望上传的文档被重用来创建多个协议,并且可以独立地获取它的文档,你应该使用POST/libraryDocument

创建libraryDocument。

你可以对这些库文档进行GET API调用,以获取文档、auditTrail等各种细节。这里有一个文档链接,你可以通过这个链接了解更多关于库文档的信息