{
  "info": {
    "name": "SignSecure Templates API ? Staging",
    "description": "Template API requests for staging. Set apiKey and templateId before use. Get Document Creation Payload returns editable JSON for Create Document from Template; replace example contacts and required prefill values. Run requests individually: this collection includes create, update, archive and delete actions. Upload the PDF using the returned presigned upload fields before using a new template.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api-stg.signpad.signsecure.in/api/v1",
      "type": "string"
    },
    {
      "key": "apiKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "templateId",
      "value": "",
      "type": "string"
    },
    {
      "key": "envelopeId",
      "value": "",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "Templates",
      "description": "Create, inspect, edit, archive, restore, duplicate, and use PDF templates with recipient assignments and sender-prefill values.",
      "item": [
        {
          "name": "Create Template",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "if (pm.response.code === 201) {",
                  "    var jsonData = pm.response.json();",
                  "    pm.collectionVariables.set('templateId', jsonData.id);",
                  "    console.log('Template ID saved:', jsonData.id);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Customer agreement\",\n  \"fileName\": \"agreement.pdf\",\n  \"description\": \"Reusable agreement with sender prefill and a recipient signature.\",\n  \"recipients\": [\n    {\n      \"id\": \"signer\",\n      \"name\": \"Customer\",\n      \"role\": \"signer\",\n      \"order\": 1,\n      \"signatureMethod\": \"electronic\"\n    }\n  ],\n  \"formFields\": [\n    {\n      \"id\": \"company\",\n      \"fieldKey\": \"company_name\",\n      \"type\": \"text\",\n      \"pageNumber\": 1,\n      \"x\": 40,\n      \"y\": 80,\n      \"width\": 200,\n      \"height\": 24,\n      \"required\": true,\n      \"defaultValue\": \"Example Ltd\",\n      \"assignee\": {\n        \"type\": \"sender_prefill\"\n      }\n    },\n    {\n      \"id\": \"customer_signature\",\n      \"fieldKey\": \"customer_signature\",\n      \"type\": \"signature\",\n      \"pageNumber\": 1,\n      \"x\": 40,\n      \"y\": 400,\n      \"width\": 200,\n      \"height\": 50,\n      \"required\": true,\n      \"assignee\": {\n        \"type\": \"recipient\",\n        \"templateRecipientId\": \"signer\"\n      }\n    }\n  ],\n  \"workflow\": {\n    \"mode\": \"sequential\",\n    \"verificationMethod\": \"link_only\",\n    \"emailNotifications\": \"all\",\n    \"whatsappNotifications\": \"all\"\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/templates",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates"
              ]
            },
            "description": "Create a reusable PDF template with recipient placeholders, a sender-prefill field, and a signature field assigned by templateRecipientId. Placeholder recipients need no email or phone. Upload the PDF using every returned upload.fields entry and the file last before using this template. Coordinates are PDF points and pages start at 1. The company field has a sample default so CSV launches can use it; override it through prefillValues for each document as needed."
          },
          "response": [
            {
              "name": "Template Created",
              "status": "Created",
              "code": 201,
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"id\": \"tmpl_abc123\",\n  \"name\": \"Customer agreement\",\n  \"fileName\": \"agreement.pdf\",\n  \"fileKey\": \"templates/user123/tmpl_abc123/agreement.pdf\",\n  \"upload\": {\n    \"url\": \"https://bucket.s3.amazonaws.com/\",\n    \"fields\": {\n      \"key\": \"templates/user123/tmpl_abc123/agreement.pdf\",\n      \"Content-Type\": \"application/pdf\",\n      \"x-amz-server-side-encryption\": \"AES256\",\n      \"X-Amz-Algorithm\": \"AWS4-HMAC-SHA256\",\n      \"X-Amz-Credential\": \"...\",\n      \"Policy\": \"base64-encoded-policy\",\n      \"X-Amz-Signature\": \"...\"\n    }\n  },\n  \"expiresIn\": 3600,\n  \"maxFileSize\": 10485760,\n  \"createdAt\": \"2026-03-10T12:00:00.000Z\",\n  \"recipientsCount\": 1\n}"
            }
          ]
        },
        {
          "name": "List All Templates",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/templates?page=1&limit=50",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1",
                  "description": "Page number (default: 1)"
                },
                {
                  "key": "limit",
                  "value": "50",
                  "description": "Items per page (default: 50)"
                },
                {
                  "key": "status",
                  "value": "active",
                  "description": "Filter by status: active, archived",
                  "disabled": true
                },
                {
                  "key": "search",
                  "value": "",
                  "description": "Search templates by name",
                  "disabled": true
                },
                {
                  "key": "sortBy",
                  "value": "createdAt",
                  "description": "Sort by: name, createdAt, usageCount",
                  "disabled": true
                },
                {
                  "key": "sortOrder",
                  "value": "desc",
                  "description": "Sort order: asc, desc",
                  "disabled": true
                }
              ]
            },
            "description": "List all templates with pagination, filtering, and sorting.\n\n**Filters:**\n- `status`: `active` or `archived`\n- `search`: Search by template name\n\n**Sorting:**\n- `sortBy`: `name`, `createdAt`, `usageCount`\n- `sortOrder`: `asc`, `desc`"
          },
          "response": [
            {
              "name": "Templates List",
              "status": "OK",
              "code": 200,
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"items\": [\n    {\n      \"id\": \"tmpl_abc123\",\n      \"name\": \"Customer agreement\",\n      \"description\": \"Reusable agreement with sender prefill and a recipient signature.\",\n      \"fileName\": \"agreement.pdf\",\n      \"status\": \"active\",\n      \"usageCount\": 5,\n      \"recipientsCount\": 1,\n      \"createdAt\": \"2026-03-10T12:00:00.000Z\",\n      \"updatedAt\": \"2026-03-10T12:00:00.000Z\"\n    }\n  ],\n  \"pageInfo\": {\n    \"page\": 1,\n    \"limit\": 50,\n    \"total\": 1,\n    \"totalPages\": 1,\n    \"hasNext\": false,\n    \"hasPrevious\": false\n  }\n}"
            }
          ]
        },
        {
          "name": "Get Template by ID",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/templates/{{templateId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates",
                "{{templateId}}"
              ]
            },
            "description": "Read recipients, their stable IDs, formFields, workflow, status, and usage statistics. Use this configuration to construct recipientMapping and prefillValues. Generated field/recipient IDs must be read from this response before use."
          },
          "response": [
            {
              "name": "Template Details",
              "status": "OK",
              "code": 200,
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"id\": \"tmpl_abc123\",\n  \"name\": \"Customer agreement\",\n  \"description\": \"Reusable agreement with sender prefill and a recipient signature.\",\n  \"fileName\": \"agreement.pdf\",\n  \"fileSize\": 204800,\n  \"status\": \"active\",\n  \"recipients\": [\n    {\n      \"id\": \"signer\",\n      \"name\": \"Customer\",\n      \"role\": \"signer\",\n      \"order\": 1,\n      \"signatureMethod\": \"electronic\"\n    }\n  ],\n  \"workflow\": {\n    \"mode\": \"sequential\",\n    \"verificationMethod\": \"link_only\",\n    \"emailNotifications\": \"all\",\n    \"whatsappNotifications\": \"all\"\n  },\n  \"usageCount\": 5,\n  \"lastUsedAt\": \"2026-03-09T10:00:00.000Z\",\n  \"createdAt\": \"2026-03-01T12:00:00.000Z\",\n  \"updatedAt\": \"2026-03-09T10:00:00.000Z\",\n  \"formFields\": [\n    {\n      \"id\": \"company\",\n      \"fieldKey\": \"company_name\",\n      \"type\": \"text\",\n      \"pageNumber\": 1,\n      \"x\": 40,\n      \"y\": 80,\n      \"width\": 200,\n      \"height\": 24,\n      \"required\": true,\n      \"defaultValue\": \"Example Ltd\",\n      \"assignee\": {\n        \"type\": \"sender_prefill\"\n      }\n    },\n    {\n      \"id\": \"customer_signature\",\n      \"fieldKey\": \"customer_signature\",\n      \"type\": \"signature\",\n      \"pageNumber\": 1,\n      \"x\": 40,\n      \"y\": 400,\n      \"width\": 200,\n      \"height\": 50,\n      \"required\": true,\n      \"assignee\": {\n        \"type\": \"recipient\",\n        \"templateRecipientId\": \"signer\"\n      }\n    }\n  ]\n}"
            }
          ]
        },
        {
          "name": "Get Document Creation Payload",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/templates/{{templateId}}/document-payload",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates",
                "{{templateId}}",
                "document-payload"
              ]
            },
            "description": "Get an editable request body for POST /templates/{{templateId}}/documents. The response contains title, recipientMapping with stable template recipient IDs and example contacts, and prefillValues for sender fields. Replace example contact details and prefill values before generating the document. Requires template read access."
          },
          "response": []
        },
        {
          "name": "Update Template",
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Updated customer agreement\",\n  \"description\": \"Revised agreement wording\",\n  \"formFields\": [\n    {\n      \"id\": \"company\",\n      \"fieldKey\": \"company_name\",\n      \"type\": \"text\",\n      \"pageNumber\": 1,\n      \"x\": 40,\n      \"y\": 80,\n      \"width\": 200,\n      \"height\": 24,\n      \"required\": true,\n      \"defaultValue\": \"Example Ltd\",\n      \"assignee\": {\n        \"type\": \"sender_prefill\"\n      }\n    },\n    {\n      \"id\": \"customer_signature\",\n      \"fieldKey\": \"customer_signature\",\n      \"type\": \"signature\",\n      \"pageNumber\": 1,\n      \"x\": 40,\n      \"y\": 400,\n      \"width\": 200,\n      \"height\": 50,\n      \"required\": true,\n      \"assignee\": {\n        \"type\": \"recipient\",\n        \"templateRecipientId\": \"signer\"\n      }\n    }\n  ],\n  \"workflow\": {\n    \"mode\": \"sequential\",\n    \"verificationMethod\": \"link_only\",\n    \"emailNotifications\": \"all\",\n    \"whatsappNotifications\": \"all\"\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/templates/{{templateId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates",
                "{{templateId}}"
              ]
            },
            "description": "Update metadata, recipients, formFields, workflow, or status. Supply at least one property. Arrays replace stored configuration; formFields: [] clears all fields. If recipient IDs change, update their field assignments in the same request. Requires template ownership and template management access."
          },
          "response": [
            {
              "name": "Template Updated",
              "status": "OK",
              "code": 200,
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"id\": \"tmpl_abc123\",\n  \"name\": \"Updated customer agreement\",\n  \"description\": \"Revised agreement wording\",\n  \"recipientsCount\": 1,\n  \"updatedAt\": \"2026-03-10T13:00:00.000Z\",\n  \"status\": \"active\",\n  \"formFieldsCount\": 2\n}"
            }
          ]
        },
        {
          "name": "Archive Template",
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/templates/{{templateId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates",
                "{{templateId}}"
              ]
            },
            "description": "Prevent new uses while preserving the reusable configuration. Existing documents remain independent.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"status\": \"archived\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": [
            {
              "name": "Archived",
              "status": "OK",
              "code": 200,
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"id\": \"tmpl_abc123\",\n  \"name\": \"Customer agreement\",\n  \"description\": \"Reusable agreement with sender prefill and a recipient signature.\",\n  \"recipientsCount\": 1,\n  \"status\": \"archived\",\n  \"formFieldsCount\": 2,\n  \"updatedAt\": \"2026-09-10T12:00:00.000Z\"\n}"
            }
          ]
        },
        {
          "name": "Restore Template",
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/templates/{{templateId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates",
                "{{templateId}}"
              ]
            },
            "description": "Restore an archived template so it can create new draft documents.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"status\": \"active\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": [
            {
              "name": "Active",
              "status": "OK",
              "code": 200,
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"id\": \"tmpl_abc123\",\n  \"name\": \"Customer agreement\",\n  \"description\": \"Reusable agreement with sender prefill and a recipient signature.\",\n  \"recipientsCount\": 1,\n  \"status\": \"active\",\n  \"formFieldsCount\": 2,\n  \"updatedAt\": \"2026-09-10T12:00:00.000Z\"\n}"
            }
          ]
        },
        {
          "name": "Delete Template",
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/templates/{{templateId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates",
                "{{templateId}}"
              ]
            },
            "description": "Permanently delete a template."
          },
          "response": [
            {
              "name": "Template Deleted",
              "status": "No Content",
              "code": 204,
              "header": [],
              "body": ""
            }
          ]
        },
        {
          "name": "Create Document from Template",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "if (pm.response.code === 201) {",
                  "    var jsonData = pm.response.json();",
                  "    pm.collectionVariables.set('envelopeId', jsonData.envelopeId);",
                  "    console.log('Envelope ID saved:', jsonData.envelopeId);",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"title\": \"NDA - Acme Corp\",\n  \"recipientMapping\": [\n    {\n      \"templateRecipientId\": \"signer\",\n      \"name\": \"Alice Johnson\",\n      \"email\": \"alice@acmecorp.com\",\n      \"phone\": \"+14155552671\"\n    }\n  ],\n  \"workflow\": {\n    \"mode\": \"sequential\",\n    \"verificationMethod\": \"link_only\",\n    \"message\": \"Please sign this NDA.\",\n    \"emailNotifications\": \"all\",\n    \"whatsappNotifications\": \"all\"\n  },\n  \"prefillValues\": [\n    {\n      \"fieldId\": \"company\",\n      \"fieldKey\": \"company_name\",\n      \"value\": \"Acme Corp\"\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/templates/{{templateId}}/documents",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates",
                "{{templateId}}",
                "documents"
              ]
            },
            "description": "Create a draft using an active, uploaded template. Map every recipient exactly once to a real email or E.164 phone. Sender-prefill entries must match both fieldId and fieldKey. Missing required values, unknown or duplicate mappings return 400; archived templates return 409. Saves envelopeId; send the draft separately through POST /documents/{{envelopeId}}/send."
          },
          "response": [
            {
              "name": "Envelope Created from Template",
              "status": "Created",
              "code": 201,
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"envelopeId\": \"doc_xyz789\",\n  \"documentId\": \"doc_xyz789\",\n  \"message\": \"Document created successfully from template\",\n  \"status\": \"draft\"\n}"
            }
          ]
        },
        {
          "name": "Duplicate Template",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"newName\": \"NDA Template (Copy)\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/templates/{{templateId}}/copies",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "templates",
                "{{templateId}}",
                "copies"
              ]
            },
            "description": "Copy the selected template. Saves templateCopyId separately so the original templateId remains available."
          },
          "response": [
            {
              "name": "Template Duplicated",
              "status": "Created",
              "code": 201,
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"id\": \"tmpl_copy456\",\n  \"name\": \"NDA Template (Copy)\",\n  \"createdAt\": \"2026-03-10T13:00:00.000Z\"\n}"
            }
          ],
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 201) {",
                  "    const data = pm.response.json();",
                  "    if (data.id) pm.collectionVariables.set(\"templateCopyId\", data.id);",
                  "}"
                ]
              }
            }
          ]
        }
      ]
    }
  ]
}