Find a Data Source Database
{ findDatabaseByName }
Return a list of databases based on search string and parent server ID
Method
/API2/dataSources/findDatabaseByName
API Section: /API2/dataSources
API Version: 2.0
From Release: 2018.5
Method operates via POST actions only.
Input Parameters
The search criteria for finding materialized data elements.
Output Response
Description of Response Type
The search results object. Note that the response is returned as a list of items of this object type.
Examples
Setting Data Model Security (JavaScript):
This example demonstrates how to set hierarchy, measure adn member level security in a data model programmatically.
The example uses API authentication driven from JavaScript. See Authentication APIs for alternatives.
var pyramidURL = "http://mysite.com/api2/";
let token = callApi("auth/authenticateUser",{
"data":{
"userName":"adminUser",
"password":"abc123!"
}
},false);
log("got token "+token);
let server= callApi("dataSources/findServerByName ",{
"searchCriteria": {
"searchValue":"Pyramid IMDB"
},
"auth": token
});
let serverId = server.data[0].itemId
let database= callApi("dataSources/findDatabaseByName ",{
"searchCriteria":{
"dataContainerId":serverId,
searchCriteria:{
"searchValue":"PyramidDemo"
}
},
"auth": token
});
let databaseId = database.data[0].itemId
let model= callApi("dataSources/findModelByName ",{
"searchCriteria":{
"dataContainerId":databaseId,
searchCriteria:{
"searchValue":"PyramidDemo"
}
},
"auth": token
});
let modelId = model.data[0].itemId
let role= callApi("access/getRolesByName ",{
searchCriteria:{
"searchValue":"role 1"
},
"auth": token
});
let roleId = role.data[0].roleId
let addMembersSecurityToModel= callApi("dataSources/addMembersSecurityToModel ",{
"hierarchyMeasureSecurityApiObject":{
"modelId":modelId,
"roleId":roleId,
"isEnableMode": true,
"hierarchyUniqueName": "[Date].[year]",
"members":["2009", "2010"]
},
"auth": token
});
let addMembersSecurityToModel= callApi("dataSources/addMembersSecurityToModel ",{
"hierarchyMeasureSecurityApiObject":{
"modelId":modelId,
"roleId":roleId,
"isEnableMode": true,
"hierarchyUniqueName": "[Geography].[Country]",
"script":"NonEmpty([Geography].[Country].AllMembers, {StrToMember([Security].[User],UserName())})"
},
"auth": token
});
let addMembersSecurityToModel= callApi("dataSources/addMembersSecurityToModel ",{
"hierarchyMeasureSecurityApiObject":{
"modelId":modelId,
"roleId":roleId,
"isEnableMode": true,
"hierarchyUniqueName": "[Security].[User]",
"script":"StrToMember([Org].[UserIds],UserName())"
},
"auth": token
});
let addHierarchySecurityToModel= callApi("dataSources/addHierarchySecurityToModel ",{
"hierarchyMeasureSecurityApiObject":{
"modelId":modelId,
"roleId":roleId,
"isEnableMode": false,
"uniqueNames": ["[Customer].[State]"]
},
"auth": token
});
let addMeasureSecurityToModel= callApi("dataSources/addMeasureSecurityToModel ",{
"hierarchyMeasureSecurityApiObject":{
"modelId":modelId,
"roleId":roleId,
"isEnableMode": true,
"uniqueNames": ["[measures].[Cost]"]
},
"auth": token
});
function log(msg){
document.write(msg);
console.log(msg);
}
function callApi(path,data,parseResult=true){
var xhttp = new XMLHttpRequest();
xhttp.open("POST", pyramidURL+path, false);
xhttp.send(JSON.stringify(data));
if(parseResult){
return JSON.parse(xhttp.responseText);
}else{
return xhttp.responseText;
}
}