صادقSadq®
GuidesAdmin
All Guides

Initiate Envelope by Template Guide

Step-by-step guide to building a reusable signing template in the Sadq portal, then initiating an envelope from it and sending the signing invitation via the API.

Overview

The Template Model lets you design a document once — in the Sadq portal — and reuse it via the API any time you need that same document signed again. You build the template visually (add text fields the creator will fill in, add signer fields for whoever needs to sign), and from then on you only need to pass a templateId to generate a new envelope. No file upload, no re-specifying field positions on every call.

Key characteristics:

  • The document, its text fields, and its signer roles are designed once, visually, in the template editor.
  • Each custom field gets a Field Label when you build the template (e.g. txtName) — that label becomes the key you use later to fill in real data via creatorFields.
  • Initiating from a template returns the full destinations array already populated with each signer's field positions, calculated from where you placed them on the PDF — you only need to fill in their contact info before inviting them.
  • Sandbox OTP for portal login is 1234.

Step 1 — Build the Template (Sadq Portal)

Do this once per document type. You only repeat Steps 2–5 below for every new signing request.

  1. Log in to the Sadq portal and go to Templates > Upload From Document Templates. Click Create New Template and upload your PDF (or click Edit next to an existing template).
  2. In the template editor, with Creator selected under Manage Recipients, drag a Text field from the field palette onto the PDF wherever it belongs. In the Field Options panel, set Field Label to a short identifier (e.g. txtName) — this is the ID you'll use later to fill the field with real data.
  3. Click Manage Recipients > Add External Signer and give the signer a name (e.g. External_1). They now appear as a recipient alongside Creator.
  4. Select the external signer's tab under Manage Recipients, drag a Signature field onto the PDF where they should sign, and click Save Template.
  5. Grab the templateId — either from the editor's URL or via GET /api/v1/templates.

Note: Repeat steps 2–4 for as many text fields and signers as the document needs. Every custom text field needs its own Field Label; every signer needs at least one field placed for them.

Step 2 — Authenticate

Call this before any other API. Send credentials as application/x-www-form-urlencoded with Basic Auth header. The returned JWT is valid for approximately 27.5 hours (99,200 seconds). Include it as Authorization: Bearer <token> on every subsequent request.

MethodEndpointPurpose
POST/Authentication/Authority/TokenObtain JWT Bearer token

Step 3 — Initiate the Envelope from the Template

MethodEndpointContent Type
POST/api/v1/envelopes/initiate-by-templatemultipart/form-data

Request fields

FieldRequiredDescription
TemplateIdYesThe template built in Step 1
WebhookIdNoID of a registered webhook to notify on completion
ReferenceNumberNoYour own tracking reference
PasswordNoOptional document password protection
AllowUserToDownloadDocumentNoLets the signer download the document from the self-service portal

Response fields

FieldDescription
data.documentIdUnique ID for the document — use this in Send Invitation
data.envelopeIdUnique ID for the envelope
data.destinationsEvery signer you added in the template, with their field positions already calculated — pass back largely unchanged in Step 4
data.creatorFieldsOne entry per Field Label you set on a text field (e.g. txtName), with an empty value — fill these in before Step 4
data.referenceNumberYour reference number
errorCode0 = success, non-zero = error (see Error Codes)

Note: Unlike the plain upload workflow, you don't define destinations or signature positions on this call — they come back pre-built from the template.

Example request

curl -X POST 'https://sandbox-api.sadq-sa.com/api/v1/envelopes/initiate-by-template' \ -H 'Authorization: Bearer {token}' \ -F 'TemplateId=bce3243b-b703-44e2-8a2b-584965bbc6cb'

Example response

{ "data": { "documentId": "aeb2b9ef-f390-4073-813e-25f7e03a3271", "envelopeId": "3b3eb464-af37-4408-a6d7-31de7093a77e", "destinations": [ { "destinationName": "External_1", "destinationEmail": null, "destinationPhoneNumber": "", "signeOrder": 0, "signatories": [ { "positionX": 330.05997, "positionY": 214.34555, "signatureHigh": 45.09373, "signatureWidth": 134.11014, "pageNumber": 1, "text": "", "type": "Signature", "fieldLabel": null, "fontFamily": "F772B5DD-B9D3-4C67-B9AA-3ECB22BF3121", "fontSize": 12, "appendDate": false, "documentId": null, "isRequired": true, "textAlignment": 0, "dataSource": null } ], "availableTo": "2026-07-18T00:00:00+03:00", "consentOnly": false, "authenticationType": 0, "allowUserToSignAnyWhere": false, "destinationType": 1, "nationalId": null, "invitationLanguage": null, "redirectUrl": null, "allowUserToAddDestination": false, "delegaterId": null, "commercialNumber": null, "uploadFile": null, "dailyNotify": false, "escalation": null } ], "referenceNumber": "Req-A-2026-381", "creatorFields": { "txtName": "" } }, "errorCode": 0, "message": "Success", "returnUrl": "/dashboard", "stateValidationErrors": null, "signature": "" }

Step 4 — Send the Invitation

Take the destinations array from Step 3 as-is, fill in each signer's destinationEmail and/or destinationPhoneNumber (at least one is required), and fill creatorFields with the real values you want printed in the document.

MethodEndpointKey Difference
POST/api/v1/invitationsStandard — by documentId. Sadq sends email/SMS. No link in response.
POST/api/v2/invitationsReturns invitationLink in response. No email/SMS sent.
POST/api/v3/invitationsBest of both — Sadq sends email/SMS AND returns invitationLink.

Request fields

FieldRequiredDescription
DocumentIdYesFrom the Step 3 response
DestinationsYesSame array returned by Step 3 — filled in with real destinationEmail/destinationPhoneNumber
CreatorFieldsNoSame keys returned by Step 3 (e.g. txtName) — fill in the real value for each
InvitationMessageNoCustom message shown to the signer
InvitationSubjectNoCustom email subject
SendUserInvitationNoDefault true — set false to create without notifying yet
CustomSmsMessageNoCustom SMS text if notified by phone

Example request

{ "documentId": "aeb2b9ef-f390-4073-813e-25f7e03a3271", "destinations": [ { "destinationName": "External_1", "destinationEmail": "ahmed@example.com", "destinationPhoneNumber": "", "signeOrder": 0, "signatories": [ { "positionX": 330.05997, "positionY": 214.34555, "signatureHigh": 45.09373, "signatureWidth": 134.11014, "pageNumber": 1, "type": "Signature", "isRequired": true } ], "authenticationType": 0 } ], "creatorFields": { "txtName": "Ahmed Al-Rashid" } }

Example response

{ "data": true, "errorCode": 0, "message": "Success", "returnUrl": null, "stateValidationErrors": null, "signature": "" }

Step 5 — Track & Download

Option A — Webhook (recommended)

If WebhookId was set in Step 3, Sadq automatically POSTs to your registered URL when all signers complete or reject, with the signed PDF included as Base64 — no separate download call needed.

Option B — Poll envelope status

MethodEndpointPurpose
GET/api/v1/envelopes/{envelopeId}/statusGet current signing status and per-signer progress

Download the signed document

MethodEndpointReturns
GET/api/v1/documents/{id}/signedSigned PDF as binary file download
GET/api/v1/documents/{id}/completed/base64Signed PDF as Base64 JSON

Common Errors

Every response includes an errorCode field — 0 means success. The ones most likely to come up in this flow:

CodeNameDescription
3UnAuthorizedToken missing or doesn't have permission
8ValidationErrorRequest body failed validation — e.g. missing TemplateId, or a destination with no email and no phone
9BadRequestMalformed or invalid request
10InvalidFileIdOrRequestIdThe templateId, documentId, or envelopeId doesn't exist
100GeneralErrorUnexpected server-side error

Quick Reference

MethodEndpointStepPurpose
POST/Authentication/Authority/Token2Get Bearer token
GET/api/v1/templates1List your templates
POST/api/v1/envelopes/initiate-by-template3Create envelope from a template
POST/api/v1/invitations4Send invitation by documentId
GET/api/v1/envelopes/{envelopeId}/status5Poll signing status
GET/api/v1/documents/{id}/signed5Download signed PDF