fastify-x-signwell
documents.getCompletedPdf / documents.getEmbeddedSigningUrl / documents.getAuditTrail
Download the completed PDF, get an embedded signing URL for in-app signing, or read the audit trail.
documents.getCompletedPdf / documents.getEmbeddedSigningUrl / documents.getAuditTrail
Three document retrieval helpers: download the signed PDF, generate an embedded signing URL for in-app signing workflows, or read the document's full audit trail.
Signatures
fastify.xsignwell.documents.getCompletedPdf(
documentId: string
): Promise<Object>
fastify.xsignwell.documents.getEmbeddedSigningUrl(
documentId: string,
recipientId: string
): Promise<{ url: string; recipient: Object }>
fastify.xsignwell.documents.getAuditTrail(
documentId: string
): Promise<Object>
Params
getCompletedPdf
| Name | Type | Required | Description |
|---|---|---|---|
documentId | string | Yes | ID of a completed document. |
getEmbeddedSigningUrl
| Name | Type | Required | Description |
|---|---|---|---|
documentId | string | Yes | ID of the document. |
recipientId | string | Yes | The recipient's id within the document (from recipients[]). |
getAuditTrail
| Name | Type | Required | Description |
|---|---|---|---|
documentId | string | Yes | ID of a completed document. |
Returns
getCompletedPdf
API response object including a file_url pointing to the signed PDF download.
getEmbeddedSigningUrl
{ url: string; recipient: Object }
url is the embedded_signing_url from the recipient object. recipient is the full recipient object from the document.
getAuditTrail
Audit trail object including timestamped events for every action taken on the document.
Throws
[xSignwell] documents.getCompletedPdf: documentId (string) is required— ifdocumentIdis missing.[xSignwell] documents.getEmbeddedSigningUrl: documentId (string) is required— ifdocumentIdis missing.[xSignwell] documents.getEmbeddedSigningUrl: recipientId (string) is required— ifrecipientIdis missing.[xSignwell] Recipient <id> not found in document <id>— if therecipientIddoes not exist in the document.[xSignwell] documents.getAuditTrail: documentId (string) is required— ifdocumentIdis missing.- Re-throws SignWell API errors with
statusCodeandsignwellErrorproperties.
Examples
getCompletedPdf — download after signing
const pdf = await fastify.xsignwell.documents.getCompletedPdf("doc_abc123");
// Redirect user to download
reply.redirect(pdf.file_url);
getEmbeddedSigningUrl — in-app signing iframe
// Get the document first to find the recipient ID
const doc = await fastify.xsignwell.documents.get("doc_abc123");
const recipient = doc.recipients.find((r) => r.email === "client@example.com");
const { url } = await fastify.xsignwell.documents.getEmbeddedSigningUrl(
"doc_abc123",
recipient.id
);
// Return to front-end to embed in an iframe
return reply.send({ signingUrl: url });
getAuditTrail — compliance record
const trail = await fastify.xsignwell.documents.getAuditTrail("doc_abc123");
console.log(trail.events); // timestamped list of viewed/signed/completed events
Realistic — embedded signing flow
fastify.get("/contracts/:documentId/sign", async (request, reply) => {
const { documentId } = request.params;
const doc = await fastify.xsignwell.documents.get(documentId);
const recipient = doc.recipients.find((r) => r.email === request.user.email);
if (!recipient) {
return reply.code(403).send({ error: "You are not a signer on this document" });
}
if (recipient.status === "completed") {
return reply.send({ alreadySigned: true });
}
const { url } = await fastify.xsignwell.documents.getEmbeddedSigningUrl(
documentId,
recipient.id
);
return reply.send({ signingUrl: url });
});
See also
- documents.get — fetch document details including recipient IDs
- documents.create — create the document
- webhooks — get notified when signing completes
AI Context
package: "@xenterprises/fastify-xsignwell"
methods: fastify.xsignwell.documents.getCompletedPdf(documentId) | fastify.xsignwell.documents.getEmbeddedSigningUrl(documentId, recipientId) | fastify.xsignwell.documents.getAuditTrail(documentId)
use-when: getCompletedPdf — download the fully-signed PDF buffer | getEmbeddedSigningUrl — get a URL to embed the signing UI in your app | getAuditTrail — download the audit trail PDF
returns: getCompletedPdf/getAuditTrail → Buffer | getEmbeddedSigningUrl → { url }
