获取Docusign中多个信封ID的状态信息

时间:2014-01-23 12:26:22

标签: asp.net rest docusignapi

我在ASP.NET网站(WebForms,v4.5)工作。我正在为这个网站提供Docu-Sign集成解决方案。我尝试了REST API调用来发起电子签名请求,下载签名文档..etc(对我来说很好)。现在我正致力于获取多个信封ID的状态。 端点为{vx}/accounts/{accountid}/envelopes/status

现在,我正在进行的PUT请求产生以下错误:

  

远程服务器返回错误:(400)错误请求。

代码段如下:

string username = "YOUR_USERNAME";
string password = "YOUR_PASSWORD";
string integratorKey = "YOUR_INTEGRATOR_KEY";
string url = "https://demo.docusign.net/restapi/v2/login_information";
string baseURL = ""; 
string accountId = ""; 

string authenticateStr =
    "<DocuSignCredentials>" +
    "<Username>" + username + "</Username>" +
    "<Password>" + password + "</Password>" +
    "<IntegratorKey>" + integratorKey + "</IntegratorKey>" +
    "</DocuSignCredentials>";

// 
// STEP 1 - Login
//
try
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Headers.Add("X-DocuSign-Authentication", authenticateStr);
    request.Accept = "application/xml";
    request.Method = "GET";
    HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
    StreamReader sr = new StreamReader(webResponse.GetResponseStream());
    string responseText = sr.ReadToEnd();
    using (XmlReader reader = XmlReader.Create(new StringReader(responseText)))
    {
        while (reader.Read())
        { // Parse the xml response body
            if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "accountId"))
                accountId = reader.ReadString();
            if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "baseUrl"))
                baseURL = reader.ReadString();
        }
    }
    //
    // STEP 2 - Get Envelope Status(es)
    //

    string envlpIds = "<envelopeIds><string>2e552785-3e1c-458b-9513-9778f59b37ae</string><string>0c0844fc-148f-4c2f-a16a-765a73a8efe0</string></envelopeIds>";

    request = (HttpWebRequest)WebRequest.Create(baseURL + "/envelopes/status");
    request.Headers.Add("X-DocuSign-Authentication", authenticateStr);
    request.Accept = "application/xml";
    request.Method = "PUT";
    request.ContentType = "application/xml";
    request.ContentLength = envlpIds.Length;

    byte[] body = System.Text.Encoding.UTF8.GetBytes(envlpIds);
    Stream dataStream = request.GetRequestStream();
    dataStream.Write(body, 0, envlpIds.Length);
    dataStream.Close();

    // read the response
    webResponse = (HttpWebResponse)request.GetResponse();
    sr.Close();
    responseText = "";
    sr = new StreamReader(webResponse.GetResponseStream());
    responseText = sr.ReadToEnd();

    //--- display results
    lblmsg.Text = responseText;
}
catch (Exception ex)
{
    lblmsg.Text = ex.Message;
}

我在这里缺少什么?请帮我解决这个问题?

更新:

尝试包装信封ID如下:

<envelopeIds>
    <envelopeId>2e552785-3e1c-458b-9513-9778f59b37ae</envelopeId>
    <envelopeId>0c0844fc-148f-4c2f-a16a-765a73a8efe0</envelopeId>
</envelopeIds>

仍然遇到同样的错误。

还尝试了附加的querysting参数,如下所示:

PUT /restapi/v2/accounts/######/envelopes/status?envelope_ids=request_body

也不起作用。

2 个答案:

答案 0 :(得分:1)

乍一看,我建议您尝试使用<envelopeId>代替<string>来包装每个信封ID:

<envelopeIds>
    <envelopeId>2e552785-3e1c-458b-9513-9778f59b37ae</envelopeId>
    <envelopeId>0c0844fc-148f-4c2f-a16a-765a73a8efe0</envelopeId>
</envelopeIds>

此外,REST API指南中的代码示例包含URI的查询字符串参数/值( envelope_ids = request_body ):

PUT /restapi/v2/accounts/######/envelopes/status?envelope_ids=request_body

您可以尝试添加该查询字符串参数/值,以查看是否有任何区别。

如果这些问题都没有解决您的问题,请更新您的问题以包含您的代码生成的XML请求正文,我将尝试提供进一步的反馈。 (您可以使用Fiddler或类似工具轻松生成XML请求的跟踪。)

答案 1 :(得分:0)

在xml上尝试了六个变种后,我放弃并选择使用contentType =“application / json”

request.ContentType = "application/json";

string envlpIds = "{\"envelopeIds\":[\"2e552785-3e1c-458b-9513-9778f59b37ae\",\"0c0844fc-148f-4c2f-a16a-765a73a8efe0\"]}";