Developer

Embed e-signature signing in your own website

To let a customer sign without leaving your app, create the envelope through the API, request a signing link for one recipient and name your website as the embed origin. Show that link in an iframe, update your page from browser events, and confirm the result on your server with a webhook.

Create a link for your website

Create the envelope first, then ask for a signing link for one recipient. The slot is the recipient's number in the envelope. The embedOrigin is the exact website that will show the page: scheme and host, plus a port if you use one, with no path and no wildcard. Use a test key while you build.

The response contains the url and its expiresAt time. Treat the url like a password, and do not write it to logs.

POST /api/v1/envelopes/{id}/signing-url
Authorization: Bearer dsk_test_...

{"slot": 1, "embedOrigin": "https://app.example.com"}
  • Use https://app.example.com, not https://app.example.com/sign or https://*.example.com
  • Plain http is accepted only for a local address during development
  • Request a separate link for each website, such as staging and production

Show it in an iframe

Create the link on your server, so your API key never reaches the browser. Then put the returned url in an iframe. Create it when the signer is ready, and check that your user is allowed to sign this envelope before you return the page.

If your own site sets a Content Security Policy, allow https://docaisign.com in frame-src. Give the frame enough height, and test it on a phone-sized screen.

<iframe src="SIGNING_URL" style="width:100%;height:800px;border:0"></iframe>

Listen for signing events

The signing page tells your page what happened by sending a message to the parent window. Check the origin and the source before you trust a message.

addEventListener('message', e => {
  if (e.origin !== 'https://docaisign.com' || e.data?.source !== 'docaisign') return;
  if (e.data.event === 'signing_complete') showThanks();
});
  • ready: the signing page has loaded
  • signing_complete: the recipient finished
  • decline: the recipient declined
  • reassign: the recipient passed it to someone else

Confirm the result on your server

Browser events are for updating the screen. A user can close the tab, lose their connection or fake a message in their own browser. Before you release a service or record a contract as signed, confirm it with a webhook or by reading the envelope through the API.

Each webhook request has an X-DocAISign-Signature header, which is the HMAC-SHA256 of the raw body using your secret. Verify it before you act. Failed deliveries are retried for about 11 hours, so make your handler safe to run twice. You can also call GET /api/v1/envelopes/{id} and look for the status completed, then download the file from GET /api/v1/envelopes/{id}/documents/signed.

// Node.js
const expected = 'sha256=' + crypto.createHmac('sha256', SECRET).update(rawBody).digest('hex');
const ok = crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(req.headers['x-docaisign-signature']));
  • recipient-completed: one recipient has finished
  • envelope-completed: everyone has finished
  • recipient-declined and envelope-declined: someone declined
  • recipient-reassigned: a different person now holds that slot

Handle several signers

A link can be created only for a recipient whose turn it is. In a signing order, a request for a later recipient returns a 400 error until the earlier people have finished. The recipient-sent webhook tells you when a person's turn has started.

Recipients also receive the normal email invitation when their turn starts. For example, a customer could sign from that email before opening your page. Read the envelope first, and show a finished message if their part is done, because a link cannot be created for someone who has already finished.

Limits

Keep these rules in mind when you plan your integration.

  • Each link works in an iframe on one exact website; other websites are blocked
  • A recipient with an access code types it in the iframe, and that proof lasts 12 hours
  • Use either an iframe link or returnUrl, not both
  • Only signing is embedded; preparing and sending documents happens through the API or on DocAISign
  • Real envelopes use your plan's sends, while test envelopes are free

Common mistakes

Most failed integrations come from a small number of errors. Check these before you go live.

  • Calling the API from browser code, which exposes your key
  • Adding a path to embedOrigin, or using a different subdomain from the page that shows the frame
  • Checking e.data but not e.origin in the message listener
  • Marking a contract signed from the browser event alone
  • Forgetting to switch from a test key to a live key, so documents still carry the TEST mark

Common questions

Can a recipient with an access code sign in the iframe?

Yes. The iframe asks for the code first, then shows the document. Give the signer the code through a separate channel, or show it in your app once they have signed in to your service.

Can users prepare or send documents inside the iframe?

No. The iframe shows the signing page only, so create and send envelopes through the API.

Do test envelopes behave like real ones?

Yes, but every page is marked TEST - NOT LEGALLY BINDING and emails start with [TEST]. Use addresses you control while testing.