@@ -7,77 +7,28 @@ namespace DocuSign.CodeExamples.Examples
7
7
using System ;
8
8
using System . Collections . Generic ;
9
9
using System . Linq ;
10
- using System . Net . Http ;
11
10
using System . Threading . Tasks ;
12
11
using DocuSign . eSign . Api ;
13
12
using DocuSign . eSign . Client ;
14
13
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 ;
17
16
18
17
public static class SetConnectedFields
19
18
{
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 )
23
20
{
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 ) ;
51
23
}
52
24
53
- public static JArray FilterData ( JArray data )
25
+ public static List < TabInfo > FilterData ( List < TabInfo > connectedFields )
54
26
{
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 ( ) ;
81
32
}
82
33
83
34
public static string SendEnvelopeViaEmail (
@@ -87,7 +38,7 @@ public static string SendEnvelopeViaEmail(
87
38
string signerEmail ,
88
39
string signerName ,
89
40
string docPdf ,
90
- JObject selectedApp )
41
+ TabInfo selectedApp )
91
42
{
92
43
//ds-snippet-start:ConnectedFields1Step6
93
44
EnvelopeDefinition envelopeDefinition = MakeEnvelope ( signerEmail , signerName , docPdf , selectedApp ) ;
@@ -105,11 +56,8 @@ public static EnvelopeDefinition MakeEnvelope(
105
56
string signerEmail ,
106
57
string signerName ,
107
58
string docPdf ,
108
- JObject selectedApp )
59
+ TabInfo selectedApp )
109
60
{
110
- var appId = selectedApp [ "appId" ] ? . ToString ( ) ?? string . Empty ;
111
- JArray tabLabels = ( JArray ) selectedApp [ "tabs" ] ;
112
-
113
61
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition ( ) ;
114
62
envelopeDefinition . EmailSubject = "Please sign this document set" ;
115
63
envelopeDefinition . Status = "sent" ;
@@ -147,32 +95,24 @@ public static EnvelopeDefinition MakeEnvelope(
147
95
} ,
148
96
} ;
149
97
150
- foreach ( var tab in tabLabels )
98
+ foreach ( var tab in selectedApp . Tabs )
151
99
{
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 ;
165
105
166
106
var text = new Text
167
107
{
168
108
RequireInitialOnSharedChange = "false" ,
169
109
RequireAll = "false" ,
170
- Name = applicationName ,
110
+ Name = extensionData . ApplicationName ,
171
111
Required = "false" ,
172
112
Locked = "false" ,
173
113
DisableAutoSize = "false" ,
174
114
MaxLength = "4000" ,
175
- TabLabel = tab [ "tabLabel" ] . ToString ( ) ,
115
+ TabLabel = tab . TabLabel ,
176
116
Font = "lucidaconsole" ,
177
117
FontColor = "black" ,
178
118
FontSize = "size9" ,
@@ -187,16 +127,16 @@ public static EnvelopeDefinition MakeEnvelope(
187
127
TabType = "text" ,
188
128
ExtensionData = new ExtensionData
189
129
{
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 ,
200
140
ExtensionPolicy = "MustVerifyToSign" ,
201
141
ConnectionInstances = new List < ConnectionInstance >
202
142
{
@@ -222,5 +162,8 @@ public static EnvelopeDefinition MakeEnvelope(
222
162
}
223
163
224
164
//ds-snippet-end:ConnectedFields1Step5
165
+
166
+ private static IamClient CreateAuthenticatedClient ( string basePath , string accessToken ) =>
167
+ IamClient . Builder ( ) . WithServerUrl ( basePath ) . WithAccessToken ( accessToken ) . Build ( ) ;
225
168
}
226
169
}
0 commit comments