Skip to content

Commit ba6890c

Browse files
Merge pull request #30 from harshitav-docusign/flow-140
Get envelope documents
2 parents 931781e + 8cb6b6e commit ba6890c

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

certified-connectors/DocuSignDemo/apiDefinition.swagger.json

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@
431431
},
432432
"/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}": {
433433
"get": {
434-
"summary": "Get documents from envelope",
434+
"summary": "DEPRECATED: Get documents from envelope",
435435
"description": "Get documents from envelope",
436436
"operationId": "GetDocuments",
437437
"parameters": [
@@ -493,6 +493,65 @@
493493
"x-ms-visibility": "advanced"
494494
}
495495
},
496+
"/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}/documentsDownload": {
497+
"get": {
498+
"summary": "Get documents from an envelope",
499+
"description": "Get documents from an envelope",
500+
"operationId": "GetDocumentsV2",
501+
"parameters": [
502+
{
503+
"name": "accountId",
504+
"in": "path",
505+
"description": "Account id",
506+
"required": true,
507+
"x-ms-summary": "Account",
508+
"x-ms-test-value": "insert account id",
509+
"x-ms-dynamic-values": {
510+
"operationId": "GetLoginAccounts",
511+
"value-collection": "loginAccounts",
512+
"value-path": "accountIdGuid",
513+
"value-title": "name"
514+
},
515+
"type": "string"
516+
},
517+
{
518+
"name": "envelopeId",
519+
"in": "path",
520+
"description": "Envelope id",
521+
"required": true,
522+
"x-ms-summary": "Envelope",
523+
"x-ms-test-value": "insert envelope id",
524+
"type": "string"
525+
},
526+
{
527+
"name": "documentId",
528+
"in": "path",
529+
"description": "Provide specific document ID or use a keyword from the dropdown",
530+
"x-ms-summary": "Document id",
531+
"required": true,
532+
"x-ms-test-value": "insert document id",
533+
"type": "string",
534+
"enum": [
535+
"Archive : Get ZIP archive with documents and COC",
536+
"Certificate : Get only certificate of completion as pdf",
537+
"Combined with COC : Get all documents as single pdf",
538+
"Combined without COC : Get all documents as single pdf",
539+
"Portfolio : Get envelope documents as a PDF Portfolio"
540+
]
541+
}
542+
],
543+
"responses": {
544+
"200": {
545+
"description": "default",
546+
"schema": {
547+
"$ref": "#/definitions/GetDocumentsResponse"
548+
}
549+
}
550+
},
551+
"deprecated": false,
552+
"x-ms-visibility": "advanced"
553+
}
554+
},
496555
"/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}/tabs": {
497556
"get": {
498557
"summary": "Get document tabs from envelope",

certified-connectors/DocuSignDemo/script.csx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,35 @@ public class Script : ScriptBase
18711871
acceptHeaderValue = "application/pdf";
18721872
}
18731873

1874+
if ("GetDocumentsV2".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
1875+
{
1876+
var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
1877+
var newPath = uriBuilder.Path;
1878+
var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query);
1879+
string[] documentDownloadOptions = { "Combined", "Archive", "Certificate", "Portfolio" };
1880+
1881+
acceptHeaderValue = "application/pdf";
1882+
string documentId = null;
1883+
1884+
foreach(var downloadOption in documentDownloadOptions)
1885+
{
1886+
if (newPath.Contains(downloadOption))
1887+
{
1888+
documentId = downloadOption;
1889+
break;
1890+
}
1891+
}
1892+
1893+
if (HttpUtility.UrlDecode(uriBuilder.Path).Trim().Contains("Combined with COC"))
1894+
{
1895+
query["certificate"] = "true";
1896+
uriBuilder.Query = query.ToString();
1897+
}
1898+
1899+
uriBuilder.Path = documentId == null ? newPath.Replace("/documentsDownload", "") : newPath.Substring(0, newPath.IndexOf(documentId) + documentId.Length);
1900+
this.Context.Request.RequestUri = uriBuilder.Uri;
1901+
}
1902+
18741903
this.Context.Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeaderValue));
18751904
}
18761905

@@ -2542,9 +2571,13 @@ public class Script : ScriptBase
25422571

25432572
if (response.Content?.Headers?.ContentType != null)
25442573
{
2545-
if ("GetDocuments".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
2574+
if (("GetDocuments".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase)) ||
2575+
("GetDocumentsV2".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase)))
25462576
{
2547-
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
2577+
var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
2578+
2579+
response.Content.Headers.ContentType = uriBuilder.Path.Contains("Archive") ? new MediaTypeHeaderValue("application/zip") :
2580+
new MediaTypeHeaderValue("application/pdf");
25482581
}
25492582
else
25502583
{

0 commit comments

Comments
 (0)