2015-12-16 67 views
0

我試圖創建一個信封的休息與web api v2與C#。我可以這樣做登錄好,但是當我試圖用模板創建信封時出現此錯誤。Docusign錯誤:「ENVELOPE_IS_INCOMPLETE」,當我試圖創建一個信封C#和Json

{ 
    "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": "[email protected]", 
     "name": "Gustavo", 
     "roleName": "[email protected]", 
     "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 = "[email protected]"; 
      string recipientName = "Gustavo"; 
      string templateRole = "[email protected]"; 
      //Content-Disposition: form-data 

      string requestBody = 
          "{" + 
           "\"status\": \"sent\"," + 
           "\"emailSubject\": \"DocuSign API - Embedded Signing example\"," + 
           "\"templateId\": \"96e27a15-2763-4e05-86c8-29e7b4e30f64\"," + 
           "\"templateRoles\":{" + 
                "\"templateRole\": [{" + 
                     "\"email\": \"[email protected]\"," + 
                     "\"name\": \"Gustavo\"," + 
                     "\"roleName\": \"[email protected]\"," + 
                     "\"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()。 My HttpWebRequest.Accept =「application/json」; HttpWebRequest.ContentType =「multipart/form-data」;

我需要幫助來弄清楚我在Json和/或C#代碼中錯過了什麼。

回答

0

你的json示例只是試圖修改模板角色本身,而不是填寫發送模板的數據。嘗試將頂層服務器模板覆蓋在上面的複合模板,使用下面的內容,但輸入模板ID和收件人/角色信息(並添加客戶端用戶標識以進行嵌入式簽名):

{ 
    "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": "[email protected]", 
       "name": "John Doe", 
       "recipientId": "1", 
       "roleName": "RoleOne" 
       } 
      ] 
      } 
     } 
     ] 
    } 
    ] 
} 
相關問題