@@ -7,77 +7,28 @@ namespace DocuSign.CodeExamples.Examples
77 using System ;
88 using System . Collections . Generic ;
99 using System . Linq ;
10- using System . Net . Http ;
1110 using System . Threading . Tasks ;
1211 using DocuSign . eSign . Api ;
1312 using DocuSign . eSign . Client ;
1413 using DocuSign . eSign . Model ;
15- using Newtonsoft . Json ;
16- using Newtonsoft . Json . Linq ;
14+ using Docusign . IAM . SDK ;
15+ using TabInfo = Docusign . IAM . SDK . Models . Components . TabInfo ;
1716
1817 public static class SetConnectedFields
1918 {
20- private static readonly HttpClient Client = new HttpClient ( ) ;
21-
22- public static async Task < object > GetConnectedFieldsTabGroupsAsync ( string accountId , string accessToken )
19+ public static async Task < List < TabInfo > > GetConnectedFieldsTabGroupsAsync ( string basePath , string accountId , string accessToken )
2320 {
24- //ds-snippet-start:ConnectedFields1Step3
25- var url = $ "https://api-d.docusign.com/v1/accounts/{ accountId } /connected-fields/tab-groups";
26-
27- var requestMessage = new HttpRequestMessage ( HttpMethod . Get , url ) ;
28- //ds-snippet-end:ConnectedFields1Step3
29-
30- //ds-snippet-start:ConnectedFields1Step2
31- requestMessage . Headers . Add ( "Authorization" , $ "Bearer { accessToken } ") ;
32- requestMessage . Headers . Add ( "Accept" , "application/json" ) ;
33- //ds-snippet-end:ConnectedFields1Step2
34-
35- try
36- {
37- //ds-snippet-start:ConnectedFields1Step3
38- var response = await Client . SendAsync ( requestMessage ) ;
39- response . EnsureSuccessStatusCode ( ) ;
40-
41- var body = await response . Content . ReadAsStringAsync ( ) ;
42- var data = JsonConvert . DeserializeObject < object > ( body ) ;
43-
44- return data ;
45- //ds-snippet-end:ConnectedFields1Step3
46- }
47- catch ( HttpRequestException e )
48- {
49- throw new Exception ( $ "DocuSign API Request failed: { e . Message } ") ;
50- }
21+ var client = CreateAuthenticatedClient ( basePath , accessToken ) ;
22+ return await client . ConnectedFields . TabInfo . GetConnectedFieldsTabGroupsAsync ( accountId ) ;
5123 }
5224
53- public static JArray FilterData ( JArray data )
25+ public static List < TabInfo > FilterData ( List < TabInfo > connectedFields )
5426 {
55- //ds-snippet-start:ConnectedFields1Step4
56- var filteredData = data . Where ( item =>
57- {
58- var tabs = item [ "tabs" ] as JArray ;
59- if ( tabs == null )
60- {
61- return false ;
62- }
63-
64- foreach ( var tab in tabs )
65- {
66- var extensionData = tab [ "extensionData" ] ;
67- var tabLabel = tab [ "tabLabel" ] ? . ToString ( ) ;
68-
69- if ( ( extensionData != null && extensionData [ "actionContract" ] ? . ToString ( ) . Contains ( "Verify" ) == true ) ||
70- ( tabLabel != null && tabLabel . Contains ( "connecteddata" ) ) )
71- {
72- return true ;
73- }
74- }
75-
76- return false ;
77- } ) . ToList ( ) ;
78- //ds-snippet-end:ConnectedFields1Step4
79-
80- return new JArray ( filteredData ) ;
27+ return connectedFields
28+ . Where ( group => group . Tabs . Any ( tab =>
29+ tab . ExtensionData ? . ActionContract ? . Contains ( "Verify" ) == true ||
30+ tab . TabLabel . Contains ( "connecteddata" ) ) )
31+ . ToList ( ) ;
8132 }
8233
8334 public static string SendEnvelopeViaEmail (
@@ -87,7 +38,7 @@ public static string SendEnvelopeViaEmail(
8738 string signerEmail ,
8839 string signerName ,
8940 string docPdf ,
90- JObject selectedApp )
41+ TabInfo selectedApp )
9142 {
9243 //ds-snippet-start:ConnectedFields1Step6
9344 EnvelopeDefinition envelopeDefinition = MakeEnvelope ( signerEmail , signerName , docPdf , selectedApp ) ;
@@ -105,11 +56,8 @@ public static EnvelopeDefinition MakeEnvelope(
10556 string signerEmail ,
10657 string signerName ,
10758 string docPdf ,
108- JObject selectedApp )
59+ TabInfo selectedApp )
10960 {
110- var appId = selectedApp [ "appId" ] ? . ToString ( ) ?? string . Empty ;
111- JArray tabLabels = ( JArray ) selectedApp [ "tabs" ] ;
112-
11361 EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition ( ) ;
11462 envelopeDefinition . EmailSubject = "Please sign this document set" ;
11563 envelopeDefinition . Status = "sent" ;
@@ -147,32 +95,24 @@ public static EnvelopeDefinition MakeEnvelope(
14795 } ,
14896 } ;
14997
150- foreach ( var tab in tabLabels )
98+ foreach ( var tab in selectedApp . Tabs )
15199 {
152- var connectionKey = tab [ "extensionData" ] [ "connectionInstances" ] != null ?
153- tab [ "extensionData" ] [ "connectionInstances" ] [ 0 ] ? [ "connectionKey" ] ? . ToString ( ) : string . Empty ;
154- var connectionValue = tab [ "extensionData" ] [ "connectionInstances" ] != null ?
155- tab [ "extensionData" ] [ "connectionInstances" ] [ 0 ] ? [ "connectionValue" ] ? . ToString ( ) : string . Empty ;
156- var extensionGroupId = tab [ "extensionData" ] [ "extensionGroupId" ] ? . ToString ( ) ?? string . Empty ;
157- var publisherName = tab [ "extensionData" ] [ "publisherName" ] ? . ToString ( ) ?? string . Empty ;
158- var applicationName = tab [ "extensionData" ] [ "applicationName" ] ? . ToString ( ) ?? string . Empty ;
159- var actionName = tab [ "extensionData" ] [ "actionName" ] ? . ToString ( ) ?? string . Empty ;
160- var actionInputKey = tab [ "extensionData" ] [ "actionInputKey" ] ? . ToString ( ) ?? string . Empty ;
161- var actionContract = tab [ "extensionData" ] [ "actionContract" ] ? . ToString ( ) ?? string . Empty ;
162- var extensionName = tab [ "extensionData" ] [ "extensionName" ] ? . ToString ( ) ?? string . Empty ;
163- var extensionContract = tab [ "extensionData" ] [ "extensionContract" ] ? . ToString ( ) ?? string . Empty ;
164- var requiredForExtension = tab [ "extensionData" ] [ "requiredForExtension" ] ? . ToString ( ) ?? string . Empty ;
100+ var extensionData = tab . ExtensionData ;
101+ var connectionKey = extensionData . ConnectionInstances != null ?
102+ extensionData . ConnectionInstances [ 0 ] ? . ConnectionKey : string . Empty ;
103+ var connectionValue = extensionData . ConnectionInstances != null ?
104+ extensionData . ConnectionInstances [ 0 ] ? . ConnectionValue : string . Empty ;
165105
166106 var text = new Text
167107 {
168108 RequireInitialOnSharedChange = "false" ,
169109 RequireAll = "false" ,
170- Name = applicationName ,
110+ Name = extensionData . ApplicationName ,
171111 Required = "false" ,
172112 Locked = "false" ,
173113 DisableAutoSize = "false" ,
174114 MaxLength = "4000" ,
175- TabLabel = tab [ "tabLabel" ] . ToString ( ) ,
115+ TabLabel = tab . TabLabel ,
176116 Font = "lucidaconsole" ,
177117 FontColor = "black" ,
178118 FontSize = "size9" ,
@@ -187,16 +127,16 @@ public static EnvelopeDefinition MakeEnvelope(
187127 TabType = "text" ,
188128 ExtensionData = new ExtensionData
189129 {
190- ExtensionGroupId = extensionGroupId ,
191- PublisherName = publisherName ,
192- ApplicationId = appId ,
193- ApplicationName = applicationName ,
194- ActionName = actionName ,
195- ActionContract = actionContract ,
196- ExtensionName = extensionName ,
197- ExtensionContract = extensionContract ,
198- RequiredForExtension = requiredForExtension ,
199- ActionInputKey = actionInputKey ,
130+ ExtensionGroupId = extensionData . ExtensionGroupId ,
131+ PublisherName = extensionData . PublisherName ,
132+ ApplicationId = selectedApp . AppId ,
133+ ApplicationName = extensionData . ApplicationName ,
134+ ActionName = extensionData . ActionName ,
135+ ActionContract = extensionData . ActionContract ,
136+ ExtensionName = extensionData . ExtensionName ,
137+ ExtensionContract = extensionData . ExtensionContract ,
138+ RequiredForExtension = extensionData . RequiredForExtension . ToString ( ) ,
139+ ActionInputKey = extensionData . ActionInputKey ,
200140 ExtensionPolicy = "MustVerifyToSign" ,
201141 ConnectionInstances = new List < ConnectionInstance >
202142 {
@@ -222,5 +162,8 @@ public static EnvelopeDefinition MakeEnvelope(
222162 }
223163
224164 //ds-snippet-end:ConnectedFields1Step5
165+
166+ private static IamClient CreateAuthenticatedClient ( string basePath , string accessToken ) =>
167+ IamClient . Builder ( ) . WithServerUrl ( basePath ) . WithAccessToken ( accessToken ) . Build ( ) ;
225168 }
226169}
0 commit comments