Saturday, August 25, 2018

Docusign GO Live



Docusign go-live process is very confusing. Here are the steps below to make review pass using the JAVA SDK API calls.
Create a maven project with the following dependency.

import java.awt.Desktop;
import java.net.URI;
import java.util.List;

import org.apache.oltu.oauth2.common.token.BasicOAuthToken;

import com.docusign.esign.api.AuthenticationApi;
import com.docusign.esign.api.EnvelopesApi;
import com.docusign.esign.client.ApiClient;
import com.docusign.esign.client.Configuration;
import com.docusign.esign.client.auth.AccessTokenListener;
import com.docusign.esign.model.Envelope;
import com.docusign.esign.model.EnvelopesInformation;
import com.docusign.esign.model.LoginInformation;

public class DocusignTest {

    private static final String CODE = "";
    private static final String TOKEN = "";

    public static void main(String[] args) throws Exception {

        boolean getCode = false;
        boolean update = false;

        String integratorKey = "your integrator key which you want to promote ";
        String clientSecret = "your secret key";

        String redirectURL = "your redirect url";
        String authServerUrl = "https://account-d.docusign.com";
        String restApiUrl = "https://demo.docusign.net/restapi";

        ApiClient apiClient = new ApiClient(authServerUrl, "docusignAccessCode", integratorKey, clientSecret);
        apiClient.setBasePath(restApiUrl);
        apiClient.configureAuthorizationFlow(integratorKey, clientSecret, redirectURL);
        Configuration.setDefaultApiClient(apiClient);

        if (getCode) {
            String oauthLoginUrl = apiClient.getAuthorizationUri();
            Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
        } else {

            apiClient.getTokenEndPoint().setCode(CODE);
            apiClient.registerAccessTokenListener(new AccessTokenListener() {
                @Override
                public void notify(BasicOAuthToken token) {
                    System.out.println("Got a fresh token: " + token.getAccessToken());
                }
            });

            if (update) {
                apiClient.updateAccessToken();
                System.out.println(apiClient.getAccessToken());
            } else {
                apiClient.setAccessToken(TOKEN, 28800l);
                String accountId = getBaseUri(apiClient);

                EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
                EnvelopesApi.ListStatusChangesOptions options = envelopesApi.new ListStatusChangesOptions();
                String date = "May 22, 2018";
                options.setFromDate(date);
                EnvelopesInformation envelopes = envelopesApi.listStatusChanges(accountId, options);

                List<Envelope> envelopes1 = envelopes.getEnvelopes();
                for (Envelope envelope : envelopes1) {
                    EnvelopesApi envelopesApi1 = new EnvelopesApi();
                    Envelope env = envelopesApi1.getEnvelope(accountId, envelope.getEnvelopeId());
                    System.out.println(env.getEnvelopeId());
                    Thread.sleep(2000);
                }
            }

        }

    }

    public static String getBaseUri(ApiClient apiClient) {
        try {
            AuthenticationApi authApi = new AuthenticationApi(apiClient);
            LoginInformation loginInfo = authApi.login();
            String accountId = loginInfo.getLoginAccounts().get(0).getAccountId();
            String baseUrl = loginInfo.getLoginAccounts().get(0).getBaseUrl();
            String[] accountDomain = baseUrl.split("/v2");
            apiClient.setBasePath(accountDomain[0]);
            Configuration.setDefaultApiClient(apiClient);
            return accountId;
        } catch (Exception ex) {
            System.out.println("Error: " + ex);
            return null;
        }
    }
}
Fill all the fields "redirectURL", "integratorKey" and "clientSecret".

First, run the program by setting getCode=true;

Now copy the code from your redirect URL in the browser and assign it to "CODE" constant field.

Now make getCode = false and make update=true;

Now run and you see the "token" in the console. Copy that and assign it to the TOKEN constant field.

Now run the Program again by making update=false. If you make 20+ successful transactions ( like getting the 20+ different envelopes), your review should pass.


No comments:

Post a Comment