Docusign错误:“ENVELOPE_IS_INCOMPLETE”,当我试图创建一个信封C#和Json

时间:2015-12-16 15:41:36

标签: c# json docusignapi

我正在尝试使用C#通过rest web api v2创建一个信封。我可以登录确定,但是当我尝试使用模板创建信封时,我收到此错误。

{
  "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."
}

这是我的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"
    }
  ]
}

我的C#功能:

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

}

我使用官方Docusign网页的这些示例演示功能:initializeRequest()和getResponseBody()。 我的HttpWebRequest.Accept =“application / json”; HttpWebRequest.ContentType =“multipart / form-data”;

我需要帮助来弄清楚我在Json和/或我的C#代码中遗漏了什么。

1 个答案:

答案 0 :(得分:0)

您的json示例只是尝试修改模板角色本身,而不是填写发送模板的数据。尝试使用覆盖服务器模板的复合模板,使用下面的内容,但输入模板ID和收件人/角色信息(并添加clientuserid进行嵌入式签名):

{
  "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"
              }
            ]
          }
        }
      ]
    }
  ]
}