When we use the envelope send API end point (/signature/{userId}/envelopes/{envelopeGuid}/send), can we specify an endpoint of a web service I have deployed as the webhook Url and get all the signing events like ‘Viewed’, ‘Signed’, etc in that hosted service endpoint. Can I also expect the signed document PDF (after signing) included in the callback?
Hi @sudiptamodak Thank you for your request. In the callback the API will send all information required to do any other task but not the document itself because not all users need this. Since that to make the callback smaller and faster we do not include the document.
To get the document you can use data from the callback: in the SourceId property you will get the envelop id which you can use to get the document.
I will show the code example for our PHP SDK, if you use another platform I can share code example for it.
////Get raw data from the GroupDocs server $json = file_get_contents("php://input"); //Decode json with raw data to array $callBack_data = json_decode($json, true); //Get job id from array $envelopeId = $callBack_data["SourceId"]; $jobStatus = $callBack_data["EventType"]; if ($jobStatus == "JobCompleted") { //Create signer object $signer = new GroupDocsRequestSigner(trim($privateKey)); //Create apiClient object $apiClient = new APIClient($signer); //Create Signature Api object $signatureApi = new SignatureApi($apiClient); //Create Storage Api object $storageApi = new StorageApi($apiClient); //Get signed document from the envelop $getDocInfo = $signatureApi->GetSignatureEnvelopeDocuments($clientId, $envelopeId); if ($getDocInfo->status == "Ok") { $name = $getDocInfo->result->documents[0]->name; //Local path to the downloads folder $downloadFolder = dirname(__FILE__) . '/../../downloads'; //Check is folder exist if (!file_exists($downloadFolder)) { //If folder don't exist create it mkdir($downloadFolder); } //Obtaining file stream of downloading file and definition of folder where to download file $outFileStream = FileStream::fromHttp($downloadFolder, $name); //Download signed document $document = $signatureApi->GetSignedEnvelopeDocuments($clientId, $envelopeId, $outFileStream); } }
Best regards.
Hi @pavelteplitsky,
Thank you, for insight. Sudipta and I are working together on this. Can you provide the same instance of java SDK?
Also do you have any documentation in this regard?
Thanks
Hello, @ira.mckey
If you need to get signed document via callback with using Java SDK, then you can use next code:
ApiInvoker.getInstance().setRequestSigner(new GroupDocsRequestSigner(pkey));
Http.RawBuffer rawBuffer = request().body().asRaw();
String jsonStr = new String(rawBuffer.asBytes());
JsonNode json = Json.parse(jsonStr);
String envilopeId = json.get("SourceId").asText();
Thread.sleep(5);
SignatureApi signatureApi = new SignatureApi();
signatureApi.setBasePath(burl);
SignatureEnvelopeDocumentsResponse envelopeDocumentsResponse =
signatureApi.GetSignatureEnvelopeDocuments(cid, envilopeId);
envelopeDocumentsResponse = Utils.assertResponse(envelopeDocumentsResponse);
String resultGuid = envelopeDocumentsResponse.getResult().getDocuments().get(0).getDocumentId();
String resultName = envelopeDocumentsResponse.getResult().getDocuments().get(0).getDocumentId();
StorageApi storageApi = new StorageApi();
storageApi.setBasePath(burl);
FileStream fileStream = storageApi.GetFile(cid, burl);
String outDir = "out";
if (!new File(outDir).exists()) {
new File(outDir).mkdir();
}
if (new File(outDir + "/" + resultName).exists()) {
new File(outDir + "/" + resultName).delete();
}
new File(outDir + "/" + resultName).createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(outDir + "/" + resultName);
StreamUtils.copy(fileStream.getInputStream(), fileOutputStream);
fileOutputStream.close();
This code is presented in our demo examples here (https://github.com/groupdocs-total/groupdocs-java-samples/blob/master/app/controllers/Callbacks.java#L136) .
So, you can download our examples and test it locally. Also they are available by this web url (http://groupdocs-java-samples.herokuapp.com/
).
Documentation for our GroupDocs Cloud Java SDK you can find here (https://docs.groupdocs.com/display/gdtotalcloud/Home).
Best regards,
Evgen Efimov
Thanks for the reply. It worked for me.
For how many days does GroupDocs persist the signed document after signing?
Hi @sudiptamodak Glad to hear that the issue is resolved. As for the time period for storing the signed documents - they don’t have an expiration date.
Best regards.
Thanks for the confirmation.