{
  "name": "MendriX — SOAP server time (ExecuteRequest)",
  "nodes": [
    {
      "parameters": {},
      "id": "trigger-time-1",
      "name": "When clicking 'Execute'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "soap-name",
              "name": "soapName",
              "value": "YOUR_SOAP_NAME",
              "type": "string"
            },
            {
              "id": "soap-password",
              "name": "soapPassword",
              "value": "YOUR_SOAP_PASSWORD",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "set-time-1",
      "name": "SOAP credentials",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [440, 300]
    },
    {
      "parameters": {
        "jsCode": "// Wrap the server-time payload in the ExecuteRequest SOAP envelope.\n// Credentials come from the 'SOAP credentials' node.\nconst creds = $('SOAP credentials').first().json;\nconst payload = '<?xml version=\"1.0\" encoding=\"windows-1252\"?><EoCustomLinkRequestDateTime Type=\"TEoCustomLinkRequestDateTime\"/>';\nconst esc = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\nconst envelope = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n  <SOAP-ENV:Header>\n    <h:TAuthenticationHeader xmlns:h=\"urn:UCoSoapDispatcherBase\">\n      <UserName>${esc(creds.soapName)}</UserName>\n      <Password>${esc(creds.soapPassword)}</Password>\n    </h:TAuthenticationHeader>\n  </SOAP-ENV:Header>\n  <SOAP-ENV:Body>\n    <m:ExecuteRequest xmlns:m=\"urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap\">\n      <ARequest xsi:type=\"xsd:string\">${esc(payload)}</ARequest>\n    </m:ExecuteRequest>\n  </SOAP-ENV:Body>\n</SOAP-ENV:Envelope>`;\n\nreturn [{ json: { envelope } }];"
      },
      "id": "code-time-1",
      "name": "Build SOAP envelope",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [640, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://<your-client-name>.mendrix.cloud:5564/soap/ICustomLinkSoap",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Content-Type", "value": "text/xml; charset=utf-8" },
            { "name": "SOAPAction", "value": "\"urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap#ExecuteRequest\"" }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "text/xml; charset=utf-8",
        "body": "={{ $json.envelope }}",
        "options": { "response": { "response": { "responseFormat": "autodetect" } } }
      },
      "id": "http-time-1",
      "name": "Call ExecuteRequest",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [860, 300]
    },
    {
      "parameters": {
        "jsCode": "// The result XML is entity-escaped inside <return>. Unescape it, fail the\n// run on a Custom Link exception, then pick out the DateTime.\nconst soap = $json.data;\nconst match = soap.match(/<return[^>]*>([\\s\\S]*?)<\\/return>/);\nif (!match) throw new Error('Unexpected SOAP response: ' + soap.slice(0, 500));\nconst result = match[1]\n  .replace(/&lt;/g, '<')\n  .replace(/&gt;/g, '>')\n  .replace(/&quot;/g, '\"')\n  .replace(/&apos;/g, \"'\")\n  .replace(/&amp;/g, '&');\nif (result.includes('TEoCustomLinkException')) throw new Error(result);\nconst dt = result.match(/<DateTime>([^<]+)<\\/DateTime>/);\n\nreturn [{ json: { serverTime: dt ? dt[1] : null, result } }];"
      },
      "id": "code-time-2",
      "name": "Extract server time",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1080, 300]
    }
  ],
  "connections": {
    "When clicking 'Execute'": {
      "main": [
        [
          { "node": "SOAP credentials", "type": "main", "index": 0 }
        ]
      ]
    },
    "SOAP credentials": {
      "main": [
        [
          { "node": "Build SOAP envelope", "type": "main", "index": 0 }
        ]
      ]
    },
    "Build SOAP envelope": {
      "main": [
        [
          { "node": "Call ExecuteRequest", "type": "main", "index": 0 }
        ]
      ]
    },
    "Call ExecuteRequest": {
      "main": [
        [
          { "node": "Extract server time", "type": "main", "index": 0 }
        ]
      ]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "pinData": {},
  "meta": { "templateCredsSetupCompleted": false },
  "tags": [{ "name": "MendriX" }]
}
