{
  "info": {
    "_postman_id": "e01b7522-76c1-4006-b211-b89e44508bc5",
    "name": "PUBAPI Collection",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_exporter_id": "29022766",
    "_collection_link": "https://go.postman.co/collection/29022766-e01b7522-76c1-4006-b211-b89e44508bc5?source=collection_link"
  },
  "item": [
    {
      "name": "Authorization",
      "item": [
        {
          "name": "Get Authorization Token",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "let json = pm.response.json();\r",
                  "pm.environment.set(\"access_token\", json.access_token);\r",
                  "pm.environment.set(\"token_expires_at\", Date.now() + (json.expires_in * 1000));\r",
                  "let tokenTest = pm.environment.get(\"access_token\");\r",
                  "console.log(\"Token stored: \" + tokenTest);\r",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "auth": {
              "type": "noauth"
            },
            "method": "POST",
            "header": [],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                {
                  "key": "grant_type",
                  "value": "client_credentials",
                  "type": "text"
                },
                {
                  "key": "scope",
                  "value": "compliance_intelligence_api:read ",
                  "type": "text"
                },
                {
                  "key": "client_id",
                  "value": "{{auth_client_id}}",
                  "description": "Authorization Id",
                  "type": "text"
                },
                {
                  "key": "client_secret",
                  "value": "{{auth_secret}}",
                  "type": "text"
                },
                {
                  "key": "enhesaclientid",
                  "value": "{{enhesa_client_id}}",
                  "description": "Enhesa Customer/Client Identifier",
                  "type": "text"
                }
              ]
            },
            "url": {
              "raw": "https://{{identityBaseUrl}}/connect/token",
              "protocol": "https",
              "host": [
                "{{identityBaseUrl}}"
              ],
              "path": [
                "connect",
                "token"
              ]
            }
          },
          "response": []
        }
      ],
      "auth": {
        "type": "noauth"
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "packages": {},
            "exec": [
              ""
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "packages": {},
            "exec": [
              ""
            ]
          }
        }
      ]
    },
    {
      "name": "Compliance-Intelligence",
      "item": [
        {
          "name": "GetClientContracts",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test(\"Endpoint returns successful\", function () {\r",
                  "    let response = pm.response.json(); // Define the response variable here\r",
                  "    pm.expect(pm.response.code, 'The response did not succeed').to.equal(200);\r",
                  "});\r",
                  "\r",
                  "if (pm.response.code === 200) {\r",
                  "    let response = pm.response.json();\r",
                  "    let facilityIds = response.result.filter(f => f.active).map(f => f.id); //only map active facilities\r",
                  "\r",
                  "    if(pm.collectionVariables.get(\"automated_content_iteration\") == true){\r",
                  "        pm.environment.unset(\"facilityId\");\r",
                  "    }\r",
                  "    pm.collectionVariables.set(\"facility_ids\", JSON.stringify(facilityIds));\r",
                  "    pm.collectionVariables.set(\"facility_index\", 0);\r",
                  "\r",
                  "    console.log(\"Facility count: \" + facilityIds.length);\r",
                  "}\r",
                  "\r",
                  "\r",
                  "/* for later reference\r",
                  "\r",
                  "pm.test(\"Should return a object\", function () {\r",
                  "    pm.expect(response, 'The response is not an object').to.be.an('object');\r",
                  "});\r",
                  "\r",
                  "pm.test(\"Should contain the `apiKey` property in the response\", function () {\r",
                  "    pm.expect(response, 'The response does not contain the property').to.haveOwnProperty('apiKey');\r",
                  "});\r",
                  "\r",
                  "pm.test(\"Should return a string for the `apiKey` property\", function () {\r",
                  "    pm.expect(response.apiKey, 'The property is not a string').to.be.a('string');\r",
                  "});\r",
                  "*/\r",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "protocolProfileBehavior": {
            "disableBodyPruning": true
          },
          "request": {
            "method": "GET",
            "header": [],
            "body": {
              "mode": "file",
              "file": {}
            },
            "url": {
              "raw": "https://{{baseUrl}}/compliance-intelligence/v1/clients/{{enhesa_client_id}}/contracts",
              "protocol": "https",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "compliance-intelligence",
                "v1",
                "clients",
                "{{enhesa_client_id}}",
                "contracts"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "7",
                  "disabled": true
                },
                {
                  "key": "pageSize",
                  "value": "100",
                  "disabled": true
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "GetClientFacilities",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test(\"Endpoint returns successful\", function () {\r",
                  "    let response = pm.response.json(); // Define the response variable here\r",
                  "    pm.expect(pm.response.code, 'The response did not succeed').to.equal(200);\r",
                  "});\r",
                  "\r",
                  "if (pm.response.code === 200) {\r",
                  "    let response = pm.response.json();\r",
                  "    let facilityIds = response.result.filter(f => f.active).map(f => f.id); //only map active facilities\r",
                  "\r",
                  "    if(pm.collectionVariables.get(\"automated_content_iteration\") == true){\r",
                  "        pm.environment.unset(\"facilityId\");\r",
                  "    }\r",
                  "    pm.collectionVariables.set(\"facility_ids\", JSON.stringify(facilityIds));\r",
                  "    pm.collectionVariables.set(\"facility_index\", 0);\r",
                  "\r",
                  "    console.log(\"Facility count: \" + facilityIds.length);\r",
                  "}\r",
                  "\r",
                  "\r",
                  "/* for later reference\r",
                  "\r",
                  "pm.test(\"Should return a object\", function () {\r",
                  "    pm.expect(response, 'The response is not an object').to.be.an('object');\r",
                  "});\r",
                  "\r",
                  "pm.test(\"Should contain the `apiKey` property in the response\", function () {\r",
                  "    pm.expect(response, 'The response does not contain the property').to.haveOwnProperty('apiKey');\r",
                  "});\r",
                  "\r",
                  "pm.test(\"Should return a string for the `apiKey` property\", function () {\r",
                  "    pm.expect(response.apiKey, 'The property is not a string').to.be.a('string');\r",
                  "});\r",
                  "*/\r",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "https://{{baseUrl}}/compliance-intelligence/v1/clients/{{enhesa_client_id}}/facilities",
              "protocol": "https",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "compliance-intelligence",
                "v1",
                "clients",
                "{{enhesa_client_id}}",
                "facilities"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "2",
                  "disabled": true
                },
                {
                  "key": "pageSize",
                  "value": "100",
                  "disabled": true
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "GetClientTopics",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "test",
              "script": {
                "exec": [
                  "pm.test(\"Endpoint returns successful\", function () {\r",
                  "    let response = pm.response.json(); // Define the response variable here\r",
                  "    pm.expect(pm.response.code, 'The response did not succeed').to.equal(200);\r",
                  "});\r",
                  "\r",
                  "if (pm.response.code === 200) {\r",
                  "    let response = pm.response.json();\r",
                  "    let facilityIds = response.result.filter(f => f.active).map(f => f.id); //only map active facilities\r",
                  "\r",
                  "    if(pm.collectionVariables.get(\"automated_content_iteration\") == true){\r",
                  "        pm.environment.unset(\"facilityId\");\r",
                  "    }\r",
                  "    pm.collectionVariables.set(\"facility_ids\", JSON.stringify(facilityIds));\r",
                  "    pm.collectionVariables.set(\"facility_index\", 0);\r",
                  "\r",
                  "    console.log(\"Facility count: \" + facilityIds.length);\r",
                  "}\r",
                  "\r",
                  "\r",
                  "/* for later reference\r",
                  "\r",
                  "pm.test(\"Should return a object\", function () {\r",
                  "    pm.expect(response, 'The response is not an object').to.be.an('object');\r",
                  "});\r",
                  "\r",
                  "pm.test(\"Should contain the `apiKey` property in the response\", function () {\r",
                  "    pm.expect(response, 'The response does not contain the property').to.haveOwnProperty('apiKey');\r",
                  "});\r",
                  "\r",
                  "pm.test(\"Should return a string for the `apiKey` property\", function () {\r",
                  "    pm.expect(response.apiKey, 'The property is not a string').to.be.a('string');\r",
                  "});\r",
                  "*/\r",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "protocolProfileBehavior": {
            "disableBodyPruning": true
          },
          "request": {
            "method": "GET",
            "header": [],
            "body": {
              "mode": "file",
              "file": {}
            },
            "url": {
              "raw": "https://{{baseUrl}}/compliance-intelligence/v1/clients/{{enhesa_client_id}}/facilities/{{facilityId}}/topics?languageCode={{languageCode}}",
              "protocol": "https",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "compliance-intelligence",
                "v1",
                "clients",
                "{{enhesa_client_id}}",
                "facilities",
                "{{facilityId}}",
                "topics"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "7",
                  "disabled": true
                },
                {
                  "key": "pageSize",
                  "value": "100",
                  "disabled": true
                },
                {
                  "key": "languageCode",
                  "value": "{{languageCode}}"
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "GetClientFacilityRequirements",
          "request": {
            "method": "POST",
            "header": [],
            "body": {
              "mode": "raw",
              "raw": "{\r\n        \"fromDate\": \"{{fromDate}}\",\r\n    \"toDate\": \"{{toDate}}\"\r\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "https://{{baseUrl}}/compliance-intelligence/v1/clients/{{enhesa_client_id}}/facilities/{{facilityId}}/requirements?languageCode={{languageCode}}",
              "protocol": "https",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "compliance-intelligence",
                "v1",
                "clients",
                "{{enhesa_client_id}}",
                "facilities",
                "{{facilityId}}",
                "requirements"
              ],
              "query": [
                {
                  "key": "languageCode",
                  "value": "{{languageCode}}"
                },
                {
                  "key": "page",
                  "value": "2",
                  "disabled": true
                },
                {
                  "key": "pageSize",
                  "value": null,
                  "disabled": true
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "GetLegalFoundationById",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "let index = parseInt(pm.collectionVariables.get(\"legalFoundation_index\") || \"0\");\r",
                  "\r",
                  "if (pm.response.code === 200 ) {\r",
                  "    pm.collectionVariables.set(\"legalFoundation_index\", index + 1);\r",
                  "}"
                ],
                "type": "text/javascript",
                "packages": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  "// Workaround for known issue with managing variables in pre-requests\r",
                  "// https://stackoverflow.com/a/75302805\r",
                  "pm.test(\"pre-request script\", function () { \r",
                  "    let legalFoundationBatchIds = JSON.parse(pm.environment.get(\"legalFoundationBatchIds\")|| \"[]\");\r",
                  "    let index = parseInt(pm.collectionVariables.get(\"legalFoundation_index\") || \"0\");\r",
                  "\r",
                  "    if (pm.collectionVariables.get(\"automated_content_iteration\") == 1 ) {\r",
                  "        if(index >= legalFoundationBatchIds.length){\r",
                  "            console.log(\"✅ All legal foundations processed. Halting execution.  Run GetClientFacilityRequirements again to populate legal foundations. \");\r",
                  "            if (typeof pm.setNextRequest === 'function') {\r",
                  "                // We're in the Collection Runner or Newman\r",
                  "                pm.setNextRequest(null); // stop execution\r",
                  "            } else {\r",
                  "                // We're running manually in the UI — prevent request from continuing\r",
                  "                throw new Error(\"All legal foundations processed. Request will not be sent.\");\r",
                  "            }\r",
                  "            pm.environment.unset(\"legalFoundationBatchIds\");\r",
                  "            pm.collectionVariables.unset(\"legalFoundation_index\");\r",
                  "            pm.environment.unset(\"legalFoundationId\");\r",
                  "        }else{\r",
                  "            let currentid = legalFoundationBatchIds[index];\r",
                  "            console.log(\"Pulling record for legalFoundation \" + currentid );\r",
                  "            pm.environment.set(\"legalFoundationId\", currentid);\r",
                  "        }\r",
                  "    }\r",
                  "})"
                ],
                "type": "text/javascript",
                "packages": {}
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [],
            "url": {
              "raw": "https://{{baseUrl}}/compliance-intelligence/v1/clients/{{enhesa_client_id}}/legalFoundations/{{legalFoundationId}}",
              "protocol": "https",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "compliance-intelligence",
                "v1",
                "clients",
                "{{enhesa_client_id}}",
                "legalFoundations",
                "{{legalFoundationId}}"
              ]
            }
          },
          "response": []
        },
        {
          "name": "GetLegalFoundationByIds",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "test",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [],
            "body": {
              "mode": "raw",
              "raw": "{{legalFoundationBatchIds}}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "https://{{baseUrl}}/compliance-intelligence/v1/clients/{{enhesa_client_id}}/legalFoundations/batch",
              "protocol": "https",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "compliance-intelligence",
                "v1",
                "clients",
                "{{enhesa_client_id}}",
                "legalFoundations",
                "batch"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "3",
                  "disabled": true
                },
                {
                  "key": "pageSize",
                  "value": "5",
                  "disabled": true
                }
              ]
            }
          },
          "response": []
        }
      ],
      "auth": {
        "type": "bearer",
        "bearer": [
          {
            "key": "token",
            "value": "{{access_token}}",
            "type": "string"
          }
        ]
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "packages": {},
            "exec": [
              ""
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "packages": {},
            "exec": [
              ""
            ]
          }
        }
      ]
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "packages": {},
        "exec": [
          "utils = {\r",
          "    setFacilityList: (collection, facilityList) => {\r",
          "        collection.set(\"facility_ids\", JSON.stringify(facilityList));\r",
          "        collection.set(\"facility_index\", 0);\r",
          "\r",
          "        console.log(\"Facility count: \" + facilityList.length);\r",
          "    }\r",
          "};"
        ]
      }
    },
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "packages": {},
        "exec": [
          "utils = {\r",
          "    setFacilityList: (collection, facilityList) => {\r",
          "        collection.set(\"facility_ids\", JSON.stringify(facilityList));\r",
          "        collection.set(\"facility_index\", 0);\r",
          "\r",
          "        console.log(\"Facility count: \" + facilityList.length);\r",
          "    }\r",
          "};"
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "automated_content_iteration",
      "value": "1",
      "type": "string"
    },
    {
      "key": "facility_ids",
      "value": "",
      "type": "string"
    },
    {
      "key": "facility_index",
      "value": "",
      "type": "string"
    },
    {
      "key": "legalFoundation_index",
      "value": "",
      "type": "string"
    },
    {
      "key": "facilityId",
      "value": "",
      "type": "default"
    }
  ]
}