DocuSign RestAPI:如何使用HTTP POST请求发送pdf文档并将模板应用于文档C#

时间:2016-04-12 22:10:52

标签: c# xml httprequest docusignapi

我是REST API和DocuSign的新手。我正在尝试上传我想要应用我在帐户中创建的网页模板的文档。

这是我到目前为止的代码(我指的是以下代码https://gist.github.com/Ergin008/4165742),但它没有说明如何在我的请求中附加新的PDF文档并申请在进行API调用时,现有模板到新的pdf。任何示例代码或帮助将不胜感激。感谢。

            HttpWebRequest request = initializeRequest("https://demo.docusign.net/restapi/v2/login_information", "GET", null, username, password, integratorKey);

            string response = getResponseBody(request);

            baseURL = parseDataFromResponse(response, "baseUrl");

            Console.WriteLine("\nAPI Call Result: \n\n" + prettyPrintXml(response));


            // Request Signature using Template

            url = baseURL + "/envelopes";             

            string requestBody =
                "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
                    "<status>sent</status>" +
                    "<emailSubject>DocuSign API - Signature Request from Template</emailSubject>" +
                    "<documents>" +
                       "<document>" +
                          "<documentId>1</documentId>" +
                          "<name>Testdoc.pdf</name>" +
                          //"<PDFBytes>" + Convert.ToBase64String(fileBytes) + "</PDFBytes>" +
                      "</document>" +
                   "</documents>" +
                    "<templateId>" + templateId + "</templateId>" +
                    "<templateRoles>" +
                        "<templateRole>" +
                            "<name>" + recipientName + "</name>" +
                            "<email>" + recipientEmail + "</email>" +
                            "<roleName>" + templateRole + "</roleName>" +
                        "</templateRole>" +
                    "</templateRoles>" +
                "</envelopeDefinition>";



            request = initializeRequest(url, "POST", requestBody, username, password, integratorKey);
           // request.ContentType = "application/pdf";



            response = getResponseBody(request);

            Console.WriteLine("\nAPI Call Result: \n\n" + prettyPrintXml(response));

1 个答案:

答案 0 :(得分:0)

这是操作方法(摘自Gil的博客文章-https://www.docusign.com/blog/dsdev-why-use-composite-templates/):

"compositeTemplates": [{
    "serverTemplates": [{
    "sequence": "1",
    "templateId": "741c8b4c-xxxx-xxxx-xxxx-c03acb1a3993"
    }],
    "inlineTemplates": [{
    "recipients": {
        "signers": [{
        "email": "joe.bloggs@example.com",
        "name": "Joe Bloggs",
        "roleName": "customer"
        }]
    },
    "sequence": "2"
    }]
}]

希望这会有所帮助!