|
| 1 | +# signNow API Java SDK |
| 2 | +## v3.0.0 |
| 3 | + |
| 4 | +[](https://www.java.com/) |
| 5 | + |
| 6 | +### About SignNow |
| 7 | +SignNow is a powerful web-based e-signature solution that streamlines the signing process and overall document flow for businesses of any size. SignNow offers SaaS as well as public and private cloud deployment options using the same underlying API. With SignNow you can easily sign, share and manage documents in compliance with international data laws and industry-specific regulations. SignNow enables you to collect signatures from partners, employees and customers from any device within minutes. For more details, please, visit [SignNow API Reference](https://docs.signnow.com/docs/signnow/welcome). |
| 8 | + |
| 9 | +### Requirements |
| 10 | +- Java 11 |
| 11 | +- Maven |
| 12 | + |
| 13 | +### Installation |
| 14 | +Get SDK code from GitHub: |
| 15 | +```bash |
| 16 | +git clone https://github.com/signnow/SNJavaSDK.git |
| 17 | +``` |
| 18 | +Install dependencies |
| 19 | +```bash |
| 20 | +# We must run the API mock server first, as it is a dependency for the tests |
| 21 | +make mock-up |
| 22 | + |
| 23 | +# Install all the dependencies and run the tests |
| 24 | +mvn install |
| 25 | +``` |
| 26 | + |
| 27 | +### Configuration |
| 28 | +Copy `.env.example` to `.env` and fill your credentials in the required values. |
| 29 | +```bash |
| 30 | +cp .env.example .env |
| 31 | +``` |
| 32 | + |
| 33 | +### Credentials |
| 34 | +To run examples or use the SDK in your project, you will need API keys. Follow these steps to obtain them: |
| 35 | + |
| 36 | +1. Register for an account on SignNow [here](https://www.signnow.com/api) |
| 37 | +2. Create a new application. |
| 38 | +3. Obtain the Basic Authentication API token for your application. |
| 39 | +4. Add your email, password, and the Basic token to the .env file. |
| 40 | + |
| 41 | +Now, you are ready to use the SDK. |
| 42 | + |
| 43 | +### Run tests |
| 44 | +```bash |
| 45 | +## Run mock server locally (must be started first, before running tests) |
| 46 | +make mock-up |
| 47 | + |
| 48 | +## Run all the tests |
| 49 | +make tests |
| 50 | + |
| 51 | +## Run a specified test |
| 52 | +make test T=SdkTest |
| 53 | +make test T=TokenTest#testPostToken |
| 54 | + |
| 55 | +## Stop mock server |
| 56 | +make mock-stop |
| 57 | +``` |
| 58 | +Mock server will be available at `http://127.0.0.1:8086`. |
| 59 | +To change the host or port, edit [wiremock-config.env](./src/test/resources/wiremock-config.env) for starting WireMock, |
| 60 | +and [.env.test](./src/test/resources/.env.test) for running tests. |
| 61 | + |
| 62 | +### Usage |
| 63 | +To start using the SDK, you need to create a new instance of the SDK API client. This can be done manually or through the SdkFactory. |
| 64 | +Example of manually creating a new token: |
| 65 | +```java |
| 66 | +import com.signnow.api.user.request.UserGetRequest; |
| 67 | +import com.signnow.api.user.response.UserGetResponse; |
| 68 | +import com.signnow.Sdk; |
| 69 | +import com.signnow.core.ApiClient; |
| 70 | +import com.signnow.core.exception.SignNowApiException; |
| 71 | +import com.signnow.core.token.BearerToken; |
| 72 | + |
| 73 | +public class AuthenticateExample { |
| 74 | + public static void main(String[] args) { |
| 75 | + |
| 76 | + try { |
| 77 | + // Create a new instance of the API client containing a freshly created bearer token |
| 78 | + Sdk sdk = new Sdk(); |
| 79 | + ApiClient client = sdk |
| 80 | + .build() |
| 81 | + .authenticate() |
| 82 | + .getApiClient(); |
| 83 | + |
| 84 | + // you can save the token for further usage if you want |
| 85 | + BearerToken token = client.getBearerToken(); |
| 86 | + |
| 87 | + // or continue using client |
| 88 | + UserGetRequest request = new UserGetRequest(); |
| 89 | + UserGetResponse response = (UserGetResponse) client.send(request); |
| 90 | + |
| 91 | + System.out.println("User ID: " + response.getId()); |
| 92 | + System.out.println("User name: " + response.getFirstName()); |
| 93 | + } catch (SignNowApiException e) { |
| 94 | + System.out.println("ERROR: " + e.getMessage()); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +Example of using an already created token: |
| 101 | +```java |
| 102 | +import com.signnow.api.user.request.UserGetRequest; |
| 103 | +import com.signnow.api.user.response.UserGetResponse; |
| 104 | +import com.signnow.Sdk; |
| 105 | +import com.signnow.core.ApiClient; |
| 106 | +import com.signnow.core.exception.SignNowApiException; |
| 107 | +import com.signnow.core.token.BearerToken; |
| 108 | + |
| 109 | +public class AuthenticateExample { |
| 110 | + public static void main(String[] args) { |
| 111 | + |
| 112 | + try { |
| 113 | + // Create a new instance without authentication (no tokens) |
| 114 | + Sdk sdk = new Sdk(); |
| 115 | + ApiClient client = sdk |
| 116 | + .build() |
| 117 | + .getApiClient(); |
| 118 | + |
| 119 | + // Use previously saved token |
| 120 | + client.setBearerToken(token); |
| 121 | + |
| 122 | + // then continue using authenticated client with token |
| 123 | + UserGetRequest request = new UserGetRequest(); |
| 124 | + UserGetResponse response = (UserGetResponse) client.send(request); |
| 125 | + |
| 126 | + System.out.println("User ID: " + response.getId()); |
| 127 | + System.out.println("User name: " + response.getFirstName()); |
| 128 | + } catch (SignNowApiException e) { |
| 129 | + System.out.println("ERROR: " + e.getMessage()); |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +Example of creating a new token through SDK: |
| 136 | +```java |
| 137 | +import com.signnow.api.document.request.DocumentGetRequest; |
| 138 | +import com.signnow.api.document.response.DocumentGetResponse; |
| 139 | +import com.signnow.core.ApiClient; |
| 140 | +import com.signnow.core.exception.SignNowApiException; |
| 141 | +import com.signnow.core.factory.SdkFactory; |
| 142 | + |
| 143 | +public class DocumentGetExample { |
| 144 | + public static void main(String[] args) { |
| 145 | + |
| 146 | + // Provide your actual document ID here |
| 147 | + String documentId = "05fbed799231d85cf3471121ecd6a4221f9c5610"; |
| 148 | + |
| 149 | + try { |
| 150 | + // The required authorization token will be created automatically by SdkFactory |
| 151 | + // using your credentials from .env file |
| 152 | + ApiClient client = SdkFactory.createApiClient(); |
| 153 | + |
| 154 | + // You are now ready to send API requests using the SDK |
| 155 | + DocumentGetRequest request = new DocumentGetRequest(); |
| 156 | + request.withDocumentId(documentId); |
| 157 | + DocumentGetResponse response = (DocumentGetResponse) client.send(request); |
| 158 | + |
| 159 | + System.out.println("Document ID: " + response.getId()); |
| 160 | + System.out.println("Document Name: " + response.getDocumentName()); |
| 161 | + System.out.println("Document Owner: " + response.getUserId()); |
| 162 | + } catch (SignNowApiException e) { |
| 163 | + System.out.println("ERROR: " + e.getMessage()); |
| 164 | + } |
| 165 | + } |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +### Examples |
| 170 | +You can find more examples of API usage in the [examples](./examples) directory. |
0 commit comments