Get the default tenant ID
{ getDefaultTenant }
Returns the ID of the default tenant in the system.
Method
/API2/access/getDefaultTenant
API Section: /API2/access
API Version: 2.0
From Release: 2018.5
Method operates via POST actions only.
Output Response
Description of Response Type
Examples
Create new Active Directory user (JavaScript):
This example demonstrates how to find and add a new user and roles in Pyramid, when using Active Directory authentication.
The example uses API authentication driven from JavaScript. See Authentication APIs for alternatives.
var pyramidURL = "http://mysite.com/api2/";
let token = callApi("auth/authenticateUserWindows",{},false);
log("got token "+token);
let defaultTenantResult = callApi("access/getDefaultTenant",{
"auth": token
});
let tenantId = defaultTenantResult.data;
log("default tenant, id= "+tenantId);
let searchUsers=callApi("access/searchAdUsers",{
"ldapUsersSearch":{
"domainNetBios":"myAdDomain",
"searchValue":"Smith",
"ldapSearchType": 0,
},
"auth": token
});
let adUser = searchUsers.data[0];
log("adUser = "+adUser.firstName);
let createUser = callApi("access/createAdUser",{
"newLdapUser": {
"userName": adUser.userName,
"adminType": 0,
"clientLicenseType": 100,
"statusID": 1,
"tenantId": tenantId,
"adDomainName":"myAdDomain"
},
"auth": token
});
let userId = createUser.data.modifiedList[0].id;
log("created user "+userId);
let updateUser=callApi("access/updateAdUsers",{
"updateLdapUser":[{
"userName": adUser.userName,
"adDomainName":"myAdDomain",
"clientLicenseType": 200,
}],
"auth": token
});
let createRole=callApi("access/createRoles",{
"data": [{
"roleName": "role1",
"tenantId": tenantId,
"isGroupRole": false
},{
"roleName": "role2",
"tenantId": tenantId,
"isGroupRole": false
}],
"auth": token
});
let role1 = createRole.data.modifiedList[0].id;
let role2 = createRole.data.modifiedList[1].id;
log("created roles "+role1+","+role2);
let addUserToRole=callApi("access/addUserToRole",{
"addUserRoleData": {
"userId":userId,
"roleId":role1
},
"auth": token
});
let groups=callApi("access/searchAdGroupsForUser",{
"searchData": {
"domainNetBios":"myAdDomain",
"userName":adUser.userName
},
"auth": token
});
log("groups of " + adUser.userName" + "+JSON.stringify(groups.data));
let selectedGroup=groups.data[0];
let addRoleToAdGroup=callApi("access/changeRoleAdGroupMembership",{
"roleAdGroups": {
"roleId":role2,
"groupsToAdd":[{
"domainNetBios":selectedGroup.domainAddress,
"groupName":selectedGroup.name
}]
},
"auth": token
});
log("addRoleToAdGroup "+JSON.stringify(addRoleToAdGroup));
let groupsFound=callApi("access/getGroupsByRole",{
"roleId":role2,
"auth": token
});
log("found group "+groupsFound.data[0].name);
function log(msg){
document.write(msg);
console.log(msg);
}
function callApi(path,data,parseResult=true){
var xhttp = new XMLHttpRequest();
xhttp.withCredentials = true;
xhttp.open("POST", pyramidURL+path, false);
xhttp.send(JSON.stringify(data));
if(parseResult){
return JSON.parse(xhttp.responseText);
}else{
return xhttp.responseText;
}
}
Content Operations (JavaScript):
This example demonstrates how to manage content items in Pyramid.
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 defaultTenant=callApi("access/getDefaultTenant",{
"auth": token
}).data;
let tenentPublicFolder = callApi("content/getPublicOrGroupFolderByTenantId",{
"folderTenantObject": {
"validRootFolderType": 1,
"tenantId": defaultTenant
},
"auth": token
}).data;
let folderCreation = callApi("content/createNewFolder",{
"folderTenantObject": {
"parentFolderId": tenentPublicFolder.id,
"folderName": "new folder"
},
"auth": token
}).data;
let folderId=folderCreation.modifiedList[0].id;
let findRole = callApi("access/getRolesByName",{
"data": {
"searchValue": "role1",
"searchMatchType": 2
},
"auth": token
});
let roleId=findRole.data[0].roleId;
log("found role with id= "+ roleId);
let addRoleToFolder= callApi("content/addRoleToItem",{
"roleToItemApiData": {
"itemId": folderId,
"roleId": roleId
},
"auth": token
});
let file="http://myOtherSite.com/Sample.pie";
let pieFile=readPieFile(file);
let importContent = callApi("content/importContent",{
"pieApiObject": {
"rootFolderId": folderId,
"fileZippedData": pieFile,
"clashDefaultOption":1,
"rolesAssignmentType":3
},
"auth": token
}).data;
let itemId=Object.keys(importContent.importDscMap)[0];
let findContentItem = callApi("content/findContentItem",{
"searchParams":{
"searchString":"import",
"filterTypes":[3],
"searchMatchType":2,
"searchRootFolderType":1
},
"auth": token
}).data;
if(importContent.importDscMap[itemId][0].needsToPerformDsc){
step 10A: get item's data source connection
let correntConnectionStringId=importContent.importDscMap[itemId][0].connectionStringProperties.id
let changedDatasource = callApi("dataSources/changeDataSource",{
"dscApiData":{
"fromConnId":correntConnectionStringId,
"toConnId":"55ff277a-53ff-4c39-8f15-5651f1026a2d",
"itemId":itemId
},
"auth": token
});
}
let copyItems = callApi("content/copyItems",{
"moveItemsObject":{
"itemsForMove":[itemId],
"destinationFolder":tenentPublicFolder.id
},
"auth": token
}).data;
let removeRoleFromCreatedFolder= callApi("content/removeRolesFromItem",{
"rolesInItemRemovalObject": {
"itemId": folderId,
"roleIds": [roleId]
},
"auth": token
});
let folderDeletion = callApi("content/purgeContentItems",{
"itemIds":[folderCreation.modifiedList[0].id],
"auth": token
});
let itemSoftDeletion = callApi("content/softDeleteContentItems",{
"itemIds":[copyItems.modifiedList[0].id],
"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;
}
}
function readPieFile(file){
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.send(null);
rawFile.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
return request.responseText;
}
}
}