Skip to content

Commit fca5a79

Browse files
Merge pull request #22 from sriharip-docusign/get_doc_id
FLOW-345: DocGen: Get document id given a document name
2 parents 067127e + f2b2f11 commit fca5a79

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

certified-connectors/DocuSignDemo/apiDefinition.swagger.json

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@
293293
"description": "Account id",
294294
"required": true,
295295
"x-ms-summary": "Account",
296-
"x-ms-test-value": "insert test value",
296+
"x-ms-test-value": "insert account id",
297297
"x-ms-dynamic-values": {
298298
"operationId": "GetLoginAccounts",
299299
"value-collection": "loginAccounts",
@@ -2401,6 +2401,57 @@
24012401
"x-ms-visibility": "important"
24022402
}
24032403
},
2404+
"/accounts/{accountId}/envelopes/{envelopeId}/get_document_id": {
2405+
"get": {
2406+
"summary": "Get document id",
2407+
"description": "Get document id",
2408+
"operationId": "GetDocumentId",
2409+
"parameters": [
2410+
{
2411+
"name": "accountId",
2412+
"in": "path",
2413+
"description": "Account id",
2414+
"required": true,
2415+
"x-ms-summary": "Account",
2416+
"x-ms-test-value": "insert account id",
2417+
"x-ms-dynamic-values": {
2418+
"operationId": "GetLoginAccounts",
2419+
"value-collection": "loginAccounts",
2420+
"value-path": "accountIdGuid",
2421+
"value-title": "name"
2422+
},
2423+
"type": "string"
2424+
},
2425+
{
2426+
"name": "envelopeId",
2427+
"in": "path",
2428+
"description": "Envelope id",
2429+
"required": true,
2430+
"x-ms-summary": "Envelope",
2431+
"x-ms-test-value": "insert envelope id",
2432+
"type": "string"
2433+
},
2434+
{
2435+
"name": "documentName",
2436+
"in": "query",
2437+
"description": "File name with extension",
2438+
"required": true,
2439+
"x-ms-summary": "Document name",
2440+
"type": "string"
2441+
}
2442+
],
2443+
"responses": {
2444+
"200": {
2445+
"description": "OK",
2446+
"schema": {
2447+
"$ref": "#/definitions/EnvelopeDocument"
2448+
}
2449+
}
2450+
},
2451+
"deprecated": false,
2452+
"x-ms-visibility": "advanced"
2453+
}
2454+
},
24042455
"/signers/accounts/{accountId}/templates/{templateId}/recipients": {
24052456
"get": {
24062457
"tags": [
@@ -4033,13 +4084,13 @@
40334084
"description": "The id of the document.",
40344085
"type": "string",
40354086
"x-ms-summary": "Document Id",
4036-
"x-ms-visibility": "advanced"
4087+
"x-ms-visibility": "important"
40374088
},
40384089
"name": {
40394090
"description": "The name of the document.",
40404091
"type": "string",
40414092
"x-ms-summary": "Name",
4042-
"x-ms-visibility": "advanced"
4093+
"x-ms-visibility": "important"
40434094
}
40444095
}
40454096
},

certified-connectors/DocuSignDemo/script.csx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,13 @@ public class Script : ScriptBase
15531553
this.Context.Request.RequestUri = uriBuilder.Uri;
15541554
}
15551555

1556+
if ("GetDocumentId".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
1557+
{
1558+
var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
1559+
uriBuilder.Path = uriBuilder.Path.Replace("/get_document_id", "/documents");
1560+
this.Context.Request.RequestUri = uriBuilder.Uri;
1561+
}
1562+
15561563
if ("GetLoginAccounts".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
15571564
{
15581565
var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
@@ -1897,6 +1904,31 @@ public class Script : ScriptBase
18971904
response.Content = new StringContent(newBody.ToString(), Encoding.UTF8, "application/json");
18981905
}
18991906

1907+
if ("GetDocumentId".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
1908+
{
1909+
var body = ParseContentAsJObject(await response.Content.ReadAsStringAsync().ConfigureAwait(false), false);
1910+
var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query);
1911+
var documentName = query.Get("documentName");
1912+
var newBody = new JObject();
1913+
1914+
foreach (var documentInfo in (body["envelopeDocuments"] as JArray) ?? new JArray())
1915+
{
1916+
if (documentName.Equals(documentInfo["name"].ToString()))
1917+
{
1918+
newBody["documentId"] = documentInfo["documentIdGuid"];
1919+
newBody["name"] = documentInfo["name"];
1920+
break;
1921+
}
1922+
}
1923+
1924+
if (newBody["documentId"] == null)
1925+
{
1926+
throw new ConnectorException(HttpStatusCode.BadRequest, "ValidationFailure: No document found matching the provided name");
1927+
}
1928+
1929+
response.Content = new StringContent(newBody.ToString(), Encoding.UTF8, "application/json");
1930+
}
1931+
19001932
if (response.Content?.Headers?.ContentType != null)
19011933
{
19021934
if ("GetDocuments".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))

0 commit comments

Comments
 (0)