{
  "info": {
    "name": "DigiCalls \u00b7 SMS connection checks",
    "schema": "https://schema.postman.com/json/collection/v2.1.0/collection.json",
    "description": "Read and preview checks for DigiCalls. This collection contains no send, schedule, event-submission or configuration-writing request. Create a Postman Local Vault secret named digicalls-api-key. Use a key with account:read, sms:read and sms:templates:read. Optional Webhook/automation reads require their corresponding read permission. Run against the intended business account; a successful check does not prove carrier delivery or CRM business logic."
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{vault:digicalls-api-key}}",
        "type": "string"
      }
    ]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "const base=pm.variables.get('baseUrl');",
          "if (base !== 'https://digicalls.com' && !/^http:\\/\\/127\\.0\\.0\\.1:\\d+$/.test(base || '')) {",
          " pm.execution.skipRequest();",
          " throw new Error('Use https://digicalls.com or an isolated localhost test server.');",
          "}"
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://digicalls.com",
      "type": "string"
    },
    {
      "key": "expectedAccountId",
      "value": "",
      "type": "string",
      "description": "Optional: reject a key belonging to a different business."
    },
    {
      "key": "templateId",
      "value": "builtin:request_received",
      "type": "string"
    },
    {
      "key": "templateVersion",
      "value": "1",
      "type": "string"
    },
    {
      "key": "templateValues",
      "value": "{\"business_name\":\"Example business\",\"reference\":\"Integration check\"}",
      "type": "string"
    },
    {
      "key": "checkWebhooks",
      "value": "false",
      "type": "string"
    },
    {
      "key": "checkAutomations",
      "value": "false",
      "type": "string"
    },
    {
      "key": "messageId",
      "value": "",
      "type": "string",
      "description": "Optional: an existing message ID from your own explicit test."
    },
    {
      "key": "runId",
      "value": "",
      "type": "string",
      "description": "Optional: an existing automation run ID."
    }
  ],
  "item": [
    {
      "name": "1 \u00b7 Account and templates",
      "item": [
        {
          "name": "Identify the business",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('DigiCalls accepted the request', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  " const result = pm.response.json();",
                  " pm.test('Response has a request ID', () => pm.expect(result.requestId).to.be.a('string'));",
                  " pm.test('Account identified', () => pm.expect(result.data.object).to.eql('account'));",
                  " const expected=pm.variables.get('expectedAccountId');",
                  " if(expected) pm.test('Key belongs to expected business', () => pm.expect(result.data.id).to.eql(expected));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/api/v1/account"
          }
        },
        {
          "name": "Read available senders",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('DigiCalls accepted the request', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  " const result = pm.response.json();",
                  " pm.test('Response has a request ID', () => pm.expect(result.requestId).to.be.a('string'));",
                  " pm.test('Senders returned', () => pm.expect(result.data).to.be.an('array'));",
                  " pm.test('Sender readiness is explicit', () => result.data.forEach(s => pm.expect(s.sendingReady).to.be.a('boolean')));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/api/v1/sms/senders"
          }
        },
        {
          "name": "Read published templates",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('DigiCalls accepted the request', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  " const result = pm.response.json();",
                  " pm.test('Response has a request ID', () => pm.expect(result.requestId).to.be.a('string'));",
                  " pm.test('Templates returned', () => pm.expect(result.data).to.be.an('array'));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/api/v1/sms/templates"
          }
        },
        {
          "name": "Preview a template \u00b7 no SMS",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('DigiCalls accepted the request', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  " const result = pm.response.json();",
                  " pm.test('Response has a request ID', () => pm.expect(result.requestId).to.be.a('string'));",
                  " pm.test('Rendered text and segment count returned', () => {",
                  " pm.expect(result.data.body).to.be.a('string'); pm.expect(result.data.segments).to.be.a('number');",
                  "});",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": "{{baseUrl}}/api/v1/sms/templates/preview",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"{{templateId}}\",\n  \"version\": {{templateVersion}},\n  \"values\": {{templateValues}}\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    },
    {
      "name": "2 \u00b7 Optional connection reads",
      "item": [
        {
          "name": "Read Webhook configuration",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.variables.get('checkWebhooks') !== 'true') pm.execution.skipRequest();"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('DigiCalls accepted the request', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  " const result = pm.response.json();",
                  " pm.test('Response has a request ID', () => pm.expect(result.requestId).to.be.a('string'));",
                  " pm.test('Webhooks returned', () => pm.expect(result.data).to.be.an('array'));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/api/v1/webhooks"
          }
        },
        {
          "name": "Read automation rules",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.variables.get('checkAutomations') !== 'true') pm.execution.skipRequest();"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('DigiCalls accepted the request', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  " const result = pm.response.json();",
                  " pm.test('Response has a request ID', () => pm.expect(result.requestId).to.be.a('string'));",
                  " pm.test('Automation rules returned', () => pm.expect(result.data).to.be.an('array'));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/api/v1/sms/automations/rules"
          }
        },
        {
          "name": "Read one message status",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const id=pm.variables.get('messageId');",
                  "if (!id) pm.execution.skipRequest();",
                  "else if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id)) { pm.execution.skipRequest(); throw new Error('Set a valid messageId'); }"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('DigiCalls accepted the request', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  " const result = pm.response.json();",
                  " pm.test('Response has a request ID', () => pm.expect(result.requestId).to.be.a('string'));",
                  " pm.test('Message status returned', () => pm.expect(result.data.status).to.be.a('string'));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/api/v1/sms/messages/{{messageId}}"
          }
        },
        {
          "name": "Read one automation run",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const id=pm.variables.get('runId');",
                  "if (!id) pm.execution.skipRequest();",
                  "else if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id)) { pm.execution.skipRequest(); throw new Error('Set a valid runId'); }"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('DigiCalls accepted the request', () => pm.response.to.have.status(200));",
                  "if (pm.response.code === 200) {",
                  " const result = pm.response.json();",
                  " pm.test('Response has a request ID', () => pm.expect(result.requestId).to.be.a('string'));",
                  " pm.test('Run status returned', () => pm.expect(result.data.status).to.be.a('string'));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/api/v1/sms/automations/runs/{{runId}}"
          }
        }
      ]
    }
  ],
  "protocolProfileBehavior": {
    "followRedirects": false
  }
}
