Skip to content

Commit 6f1a070

Browse files
committed
Fix bug at prefill document fields endpoint
1 parent d20da85 commit 6f1a070

File tree

4 files changed

+76
-8
lines changed

4 files changed

+76
-8
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import com.signnow.api.document.request.DocumentPostRequest;
2+
import com.signnow.api.document.response.DocumentPostResponse;
3+
import com.signnow.api.documentfield.request.DocumentPrefillPutRequest;
4+
import com.signnow.api.documentfield.response.DocumentPrefillPutResponse;
5+
import com.signnow.core.ApiClient;
6+
import com.signnow.core.exception.SignNowApiException;
7+
import com.signnow.core.factory.SdkFactory;
8+
import com.signnow.api.documentfield.request.data.*;
9+
import com.signnow.core.response.Reply;
10+
public class DocumentPrefillTextFieldExample {
11+
public static void main(String[] args) {
12+
13+
// Set your actual input data here
14+
// Note: following values are dummy, just for example
15+
//----------------------------------------------------
16+
// if it is not specified here, a new Bearer token will be created automatically
17+
String bearerToken = "";
18+
String signerRole = "Product Manager";
19+
String pathToDocument = "/your/path/to/file.pdf";
20+
21+
try {
22+
ApiClient client = SdkFactory.createApiClientWithBearerToken(bearerToken);
23+
24+
// Upload a new document
25+
// or you can use an existing document
26+
DocumentPostRequest request = new DocumentPostRequest(new File(pathToDocument));
27+
DocumentPostResponse response = (DocumentPostResponse) client.send(request).getResponse();
28+
String documentId = response.getId();
29+
30+
// Add fields with roles to the new document
31+
var documentFields = new com.signnow.api.document.request.data.FieldCollection();
32+
documentFields.add(
33+
new com.signnow.api.document.request.data.Field(
34+
50,
35+
18,
36+
200,
37+
20,
38+
"text",
39+
0,
40+
true,
41+
signerRole,
42+
"field_1",
43+
"Reason to sign"));
44+
DocumentPutRequest putFieldsRequest = new DocumentPutRequest(documentFields);
45+
putFieldsRequest.withDocumentId(documentId);
46+
client.send(putFieldsRequest);
47+
48+
// Prefill an existing field by their name "field_1"
49+
var prefillFields = new FieldCollection();
50+
prefillFields.add(new Field("field_1", "custom prefilled text here"));
51+
DocumentPrefillPutRequest prefillPutRequest = new DocumentPrefillPutRequest(prefillFields);
52+
prefillPutRequest.withDocumentId(documentId);
53+
54+
Reply<DocumentPrefillPutResponse> responsePrefillFields = client.send(prefillPutRequest);
55+
System.out.println(responsePrefillFields.getStatusCode());
56+
} catch (SignNowApiException e) {
57+
System.out.println("ERROR: " + e.getMessage());
58+
}
59+
}
60+
}

src/main/java/com/signnow/api/documentfield/request/DocumentPrefillPutRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
namespace = "documentField",
2828
entity = "documentPrefill",
2929
type = "application/json")
30-
public final class DocumentPrefillPutRequest implements RequestInterface<String> {
30+
public final class DocumentPrefillPutRequest implements RequestInterface<Object> {
3131

3232
/**
3333
* Collection of fields to be prefilled in the document.
@@ -86,9 +86,9 @@ public HashMap<String, String> uriParams() {
8686
*/
8787
@NotNull
8888
@Override
89-
public Map<String, String> payload() {
90-
Map<String, String> map = new HashMap<>();
91-
map.put("fields", this.fields.toString());
89+
public Map<String, Object> payload() {
90+
Map<String, Object> map = new HashMap<>();
91+
map.put("fields", this.getFields());
9292
return map;
9393
}
9494
}

src/main/java/com/signnow/api/documentfield/request/data/Field.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
package com.signnow.api.documentfield.request.data;
1111

12+
import com.fasterxml.jackson.annotation.JsonCreator;
13+
import com.fasterxml.jackson.annotation.JsonProperty;
14+
1215
import java.util.HashMap;
1316
import java.util.Map;
1417

@@ -20,11 +23,13 @@ public final class Field {
2023
/**
2124
* The name of the field.
2225
*/
26+
@JsonProperty("field_name")
2327
private final String fieldName;
2428

2529
/**
2630
* The prefilled text of the field.
2731
*/
32+
@JsonProperty("prefilled_text")
2833
private final String prefilledText;
2934

3035
/**
@@ -33,7 +38,10 @@ public final class Field {
3338
* @param fieldName the name of the field
3439
* @param prefilledText the prefilled text of the field
3540
*/
36-
public Field(String fieldName, String prefilledText) {
41+
@JsonCreator
42+
public Field(
43+
@JsonProperty("field_name") String fieldName,
44+
@JsonProperty("prefilled_text") String prefilledText) {
3745
this.fieldName = fieldName;
3846
this.prefilledText = prefilledText;
3947
}
@@ -63,8 +71,8 @@ public String getPrefilledText() {
6371
*/
6472
public Map<String, String> toMap() {
6573
Map<String, String> map = new HashMap<>();
66-
map.put("field_name", getFieldName());
67-
map.put("prefilled_text", getPrefilledText());
74+
map.put("field_name", this.getFieldName());
75+
map.put("prefilled_text", this.getPrefilledText());
6876
return map;
6977
}
7078

src/main/java/com/signnow/core/config/ConfigRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class ConfigRepository {
1919

2020
private static final int READ_TIMEOUT = 15;
21-
private static final String CLIENT_NAME = "SignNow Java API Client/v3.0.0";
21+
private static final String CLIENT_NAME = "SignNowApiClient/v3.0.0 (Java)";
2222

2323
private final Map<String, String> configMap;
2424

0 commit comments

Comments
 (0)