create-a-widget

Widgets are hosted documents that can be signed by anyone who has access to them. They are ideal for signup sheets, waivers, or any document you need many people to access and sign online.

You can quickly create a Widget from a transient document as follows:

//Populate the headers
//Note that MultivaluedMap is part of javax.ws.rs.core package
//Note that MultivaluedMapImpl is part of com.sun.jersey.core.util package
MultivaluedMap headers = new MultivaluedMapImpl();    
String ACCESS_TOKEN_KEY= "Access-Token";  
String X_API_USER_KEY = "x-api-user"; 
headers.put(ACCESS_TOKEN_KEY, "hajUhhsNottheRealTokenjKh");    
headers.put(X_API_USER_KEY, "me@mycomp.com");

//Let's create our first Widget
WidgetCreationRequest widgetCreationRequest = new WidgetCreationRequest();

//The information required to create our Widget
WidgetCreationInfo widgetCreationInfo = new WidgetCreationInfo();

//The information pertaining to our uploaded transient document
ArrayList fileInfos = new ArrayList<>();

//Create a FileInfo object using the document ID
WidgetFileInfo fileInfo = new WidgetFileInfo();
fileInfo.setTransientDocumentId(documentId);

//Populate the list
fileInfos.add(fileInfo);

//Set the formFieldIdType
ArrayList formFieldLayerTemplates = new ArrayList<>();
formFieldLayerTemplates.add(fileInfo);
widgetCreationInfo.setFormFieldLayerTemplates(formFieldLayerTemplates);
widgetCreationInfo.setFileInfos(fileInfos);
widgetCreationInfo.setName("MyFirstWidget");
widgetCreationInfo.setSignatureFlow(WidgetCreationInfo.SignatureFlowEnum.SENDER_SIGNATURE_NOT_REQUIRED);
widgetCreationRequest.setWidgetCreationInfo(widgetCreationInfo);

//Create the Widget
WidgetCreationResponse widgetCreationResponse = widgetsApi.createWidget(headers, widgetCreationRequest);

//Display widget ID and corresponding code of newly created widget. 
System.out.println("Newly created widget's ID: " + widgetCreationResponse.getWidgetId()); 
System.out.println("The corresponding JavaScript code to embed the created widget: " + widgetCreationResponse.getJavascript() + "\n" + "OR \n" + "URL to host the widget: " + widgetCreationResponse.getUrl()); }}