Bisileesh
Bisileesh

Reputation: 1976

Getting status information of multiple envelope ids in Docusign

I am working in an ASP.NET website(WebForms,v4.5).I am providing a Docu-Sign integrated solution with this website.I tried REST API calls for initiating an e-Sign request,downloading a Signed document..etc(which works fine for me).Now i am working on getting status of multiple envelope ids. Here the endpoint is {vx}/accounts/{accountid}/envelopes/status

Now,the PUT request which i am making arises the following error:

The remote server returned an error: (400) Bad Request.

The code snippet is as follows:

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

What am i missing here? Please help me in fixing this?

UPDATE :

Tried wrapping envelope id as follows :

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

Still getting the same error.

Also tried the additional querysting parameter as follows :

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

which also is not working.

Upvotes: 0

Views: 595

Answers (2)

Maui Doug
Maui Doug

Reputation: 108

After trying a half a dozen variations on the xml, I gave up and opted to use the contentType = "application/json"

request.ContentType = "application/json";

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

Upvotes: 0

Kim Brandl
Kim Brandl

Reputation: 13480

Upon first glance, I'd suggest that you try using <envelopeId> instead of <string> to wrap each envelopeId:

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

Also, the code sample in the REST API guide contains a querystring parameter/value (envelope_ids=request_body) for the URI:

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

You might try adding that querystring parameter/value to see if that makes any difference.

If neither one of those things resolves your issue, then please update your question to include the XML request body that's being generated by your code, and I'll try to provide further feedback. (You can easily produce a trace of the XML request by using Fiddler or a similar tool.)

Upvotes: 1

Related Questions