简体   繁体   中英

Docusign error: “ENVELOPE_IS_INCOMPLETE” when I'm trying to create an envelope C# and Json

I'm trying to create an envelope by rest web api v2 with C#. I can do to login ok, however I get this error when I'm trying to create an envelope with a template.

{
  "errorCode": "ENVELOPE_IS_INCOMPLETE",
  "message": "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line. Content-Type does not contain boundary parameter."
}

This is my Json:

{
  "status": "sent",
  "emailSubject": "DocuSign API - Embedded Signing example",
  "templateId": "96e27a15-2763-4e05-86c8-29e7b4e30f64",
  "templateRoles": {
    "templateRole": [
      {
        "email": "micorreo@email.com",
        "name": "Gustavo",
        "roleName": "micorreo@email.com",
        "clientUserId": "1",
        "tabs": {
          "textTabs": [
            {
              "text": {
                "tabLabel": "tabLabel1",
                "value": "Value1"
              }
            }
          ]
        }
      }
    ]
  },
  "documents": [
    {
      "documentId": "1",
      "name": "My First DocuSign.docx"
    }
  ]
}

My C# function:

 public bool Create()
    {
        bool result = false;
        try
        {
            //============================================================================
            //  STEP 2 - Create an Envelope from Template and Send
            //============================================================================
            string templateId = "96e27a15-2763-4e05-86c8-29e7b4e30f64";
            // append "/envelopes" to baseURL and use for signature request api call
            string url = AccountManager.Instance.CurrentAccount.baseUrl + "/envelopes";
            string recipientEmail = "micorreo@email.com";
            string recipientName = "Gustavo";
            string templateRole = "micorreo@email.com";
            //Content-Disposition: form-data

            string requestBody =
                            "{" +
                                "\"status\": \"sent\"," +
                                "\"emailSubject\": \"DocuSign API - Embedded Signing example\"," +
                                "\"templateId\": \"96e27a15-2763-4e05-86c8-29e7b4e30f64\"," +
                                "\"templateRoles\":{" +
                                                    "\"templateRole\": [{" +
                                                                        "\"email\": \"micorreo@email.com\"," +
                                                                        "\"name\": \"Gustavo\"," +
                                                                        "\"roleName\": \"micorreo@email.com\"," +
                                                                        "\"clientUserId\": \"1\"," +
                                                                          "\"tabs\": {" +
                                                                                        "\"textTabs\": [{" +
                                                                                                        "\"text\": {" +
                                                                                                                    "\"tabLabel\": \"tabLabel1\"," +
                                                                                                                      "\"value\": \"Value1\"" +
                                                                                                                  "}" +
                                                                                                       "}]" +
                                                                                    "}" +
                                                                        "}]" +
                                                    "}," +
                                                    "\"documents\":[{" +
                                                                        "\"documentId\":\"1\"," +
                                                                                         "\"name\":\"My First DocuSign.docx\"" +
                                                                                                     "}]" +
                            "}";



            // string body = string.Format("Content-Disposition: form-data; boundary={0}", requestBody);

            // set request url, method, body, and headers
            HttpWebRequest request = HttpResponseHelper.initializeRequest(
                                                                        HttpResponseHelperConstants.REQUEST_ACCEPT_JSON,
                                                                        HttpResponseHelperConstants.CONTENT_TYPE_MULTIPART,
                                                                        url,
                                                                        "POST",
                                                                        requestBody,
                                                                        null,
                                                                        CredentialsEntity.Instance);

            // read the http response
            string response = HttpResponseHelper.getResponseBody(request);

        }        
        catch (WebException ex)
        {
            WebResponse errorResponse = ex.Response;
            using (Stream responseStream = errorResponse.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
                String errorText = reader.ReadToEnd();
                // log errorText
            }
            throw;
        }
        catch (Exception ex)
        {
            throw new DocuSignAccountException("Error when tried to create an envelope", ex);
        }

}

I use these examples demo functions of the official Docusign web page: initializeRequest() and getResponseBody(). My HttpWebRequest.Accept = "application/json"; HttpWebRequest.ContentType = "multipart/form-data";

I need help to figure out what I missed in my Json and/or in my C# code, please.

Your json sample is just trying to modify the template role itself, not fill in the data for sending the template. Try composite templates with overlaying your server template on top, use the below but input your template ID and recipient/role info (and add clientuserid for embedded signing):

{
  "emailSubject": "DocuSign API - Composite Templates",
  "emailBlurb": "Composite Templates - Server Template Sample",
  "status": "sent",
  "compositeTemplates": [
    {
      "serverTemplates": [
        {
          "sequence": "2",
          "templateId": "REPLACEME"
        }
      ],
      "inlineTemplates": [
        {
          "sequence": "1",
          "recipients": {
            "signers": [
              {
                "email": "firstrecipient@email.com",
                "name": "John Doe",
                "recipientId": "1",
                "roleName": "RoleOne"
              }
            ]
          }
        }
      ]
    }
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM