If you really want REST API based solution, there is a manifest.json end-point for each map service. e.g.
https://server.FQDN.com:6443/arcgis/admin/services/FOLDER/SERVICE.MapServer/iteminfo/manifest/manife...
This gives you details of database/FGDB connections and layers for each. e.g.
{
"databases": [
{
"byReference": true,
"onServerWorkspaceFactoryProgID": "esriDataSourcesGDB.SdeWorkspaceFactory",
"onServerConnectionString": "ENCRYPTED_PASSWORD=3345435we23232543546456567;SERVER=DBSERVER;INSTANCE=sde:sqlserver:DBSERVER;DBCLIENT=sqlserver;DB_CONNECTION_PROPERTIES=DBSERVER;DATABASE=TESTDB;USER=dbadmin;AUTHENTICATION_MODE=DBMS;BRANCH=sde.DEFAULT",
"onPremiseConnectionString": "ENCRYPTED_PASSWORD=3345435we23232543546456567;SERVER=DBSERVER;INSTANCE=sde:sqlserver:DBSERVER;DBCLIENT=sqlserver;DB_CONNECTION_PROPERTIES=DBSERVER;DATABASE=TESTDB;USER=dbadmin;AUTHENTICATION_MODE=DBMS;BRANCH=sde.DEFAULT",
"onServerName": "sde.DEFAULT (DBSERVER)",
"onPremisePath": "",
"datasets": [
{
"onServerName": "ServiceTerritory"
},
{
"onServerName": "StructureBoundary"
},
{
"onServerName": "WaterDevice"
},
{
"onServerName": "StructureLine"
},
{
"onServerName": "WaterJunction"
},
{
"onServerName": "WaterAssembly"
},
{
"onServerName": "StructureJunction"
},
{
"onServerName": "WaterLine"
},
{
"onServerName": "WaterSubnetLine"
},
{
"onServerName": "WaterDistribution"
},
{
"onServerName": "HydrantMaintenanceInspection"
},
{
"onServerName": "ValveInspection"
}
]
}
],
"resources": [
{
"onPremisePath": "D:\\TEST\\General\\UtilityNetwork\\WaterNetwork\\V2.4\\WaterDistributionUtilityNetwork.aprx",
"clientName": "DBSERVER",
"serverPath": "D:\\AGSEnterprise\\Server\\directories\\arcgissystem\\arcgisinput\\UN\\NapervilleWater.MapServer\\extracted\\p20\\NapervilleWater.msd"
}
]
}