@@ -86,7 +86,114 @@ Or you can manually download and add the following JARs to your project:
8686Usage
8787=====
8888
89- To send a signature request from a Template:
89+ To send a signature request from a Template using 3-legged OAuth:
90+
91+ ``` java
92+ import com.docusign.esign.api.* ;
93+ import com.docusign.esign.client.* ;
94+ import com.docusign.esign.model.* ;
95+
96+ import java.util.List ;
97+
98+ public class DocuSignExample {
99+ public static void main (String [] args ) {
100+ String RedirectURI = " [REDIRECT_URI]" ;
101+ String ClientSecret = " [CLIENT_SECRET]" ;
102+ String integratorKey = " [INTEGRATOR_KEY]" ;
103+ String BaseUrl = " https://demo.docusign.net/restapi" ;
104+ String OAuthBaseUrl = " https://account-d.docusign.com" ;
105+
106+ // initialize client for desired environment and add X-DocuSign-Authentication header
107+ ApiClient apiClient = new ApiClient (" https://demo.docusign.net/restapi" );
108+
109+ ApiClient apiClient = new ApiClient (OAuthBaseUrl , " docusignAccessCode" , IntegratorKey , ClientSecret );
110+ apiClient. setBasePath(BaseUrl );
111+ // make sure to pass the redirect uri
112+ apiClient. configureAuthorizationFlow(IntegratorKey , ClientSecret , RedirectURI );
113+ Configuration . setDefaultApiClient(apiClient);
114+ try
115+ {
116+ // get DocuSign OAuth authorization url
117+ String oauthLoginUrl = apiClient. getAuthorizationUri();
118+ // open DocuSign OAuth login in the browser
119+ System . out. println(oauthLoginUrl);
120+ Desktop . getDesktop(). browse(URI . create(oauthLoginUrl));
121+ // IMPORTANT: after the login, DocuSign will send back a fresh
122+ // authorization code as a query param of the redirect URI.
123+ // You should set up a route that handles the redirect call to get
124+ // that code and pass it to token endpoint as shown in the next
125+ // lines:
126+ String code = " <once_you_get_the_oauth_code_put_it_here>" ;
127+ // assign it to the token endpoint
128+ apiClient. getTokenEndPoint(). setCode(code);
129+ // optionally register to get notified when a new token arrives
130+ apiClient. registerAccessTokenListener(new AccessTokenListener () {
131+ @Override
132+ public void notify (BasicOAuthToken token ) {
133+ System . out. println(" Got a fresh token: " + token. getAccessToken());
134+ }
135+ });
136+ // ask to exchange the auth code with an access code
137+ apiClient. updateAccessToken();
138+
139+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////
140+ // STEP 1: AUTHENTICATE TO RETRIEVE ACCOUNTID & BASEURL
141+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////
142+
143+ AuthenticationApi authApi = new AuthenticationApi ();
144+ LoginInformation loginInfo = authApi. login();
145+
146+ // parse first account ID (user might belong to multiple accounts) and baseUrl
147+ String accountId = loginInfo. getLoginAccounts(). get(0 ). getAccountId();
148+ String baseUrl = loginInfo. getLoginAccounts(). get(0 ). getBaseUrl();
149+ String [] accountDomain = baseUrl. split(" /v2" );
150+
151+ // below code required for production, no effect in demo (same domain)
152+ apiClient. setBasePath(accountDomain[0 ]);
153+ Configuration . setDefaultApiClient(apiClient);
154+
155+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////
156+ // *** STEP 2: CREATE ENVELOPE FROM TEMPLATE
157+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////
158+
159+ // create a new envelope to manage the signature request
160+ EnvelopeDefinition envDef = new EnvelopeDefinition ();
161+ envDef. setEmailSubject(" DocuSign Java SDK - Sample Signature Request" );
162+
163+ // assign template information including ID and role(s)
164+ envDef. setTemplateId(" [TEMPLATE_ID]" );
165+
166+ // create a template role with a valid templateId and roleName and assign signer info
167+ TemplateRole tRole = new TemplateRole ();
168+ tRole. setRoleName(" [ROLE_NAME]" );
169+ tRole. setName(" [SIGNER_NAME]" );
170+ tRole. setEmail(" [SIGNER_EMAIL]" );
171+
172+ // create a list of template roles and add our newly created role
173+ java.util.List<TemplateRole > templateRolesList = new java.util.ArrayList<TemplateRole > ();
174+ templateRolesList. add(tRole);
175+
176+ // assign template role(s) to the envelope
177+ envDef. setTemplateRoles(templateRolesList);
178+
179+ // send the envelope by setting |status| to "sent". To save as a draft set to "created"
180+ envDef. setStatus(" sent" );
181+
182+ // instantiate a new EnvelopesApi object
183+ EnvelopesApi envelopesApi = new EnvelopesApi ();
184+
185+ // call the createEnvelope() API
186+ EnvelopeSummary envelopeSummary = envelopesApi. createEnvelope(accountId, envDef);
187+ }
188+ catch (com.docusign.esign.client. ApiException ex)
189+ {
190+ System . out. println(" Exception: " + ex);
191+ }
192+ }
193+ }
194+ ```
195+
196+ To send a signature request from a Template using username/password:
90197
91198``` java
92199import com.docusign.esign.api.* ;
0 commit comments