/////////////////////////////////////////////////////////////////////////////////////////
$.ajaxSetup({async: false});
var cache = {};
cache[ "group_id" ] ="";//"blah"
cache["baseurl"] = 'https://blah/api/v1/';
cache["user_id"] = "ws_creator";
cache["pwd"] = "test";
cache["FolderIds"] =[];
function getToken( ){
console.log("getToken");
//debugger;
return $.when(
$.ajax({
url: cache["baseurl"] +'session/login',
type: 'put',
data: JSON.stringify({
user_id:cache["user_id"],
password:cache["pwd"]
}),
headers: {
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
cache[ "Token" ] = resp["X-Auth-Token"];
console.log("getToken:success");
},
failure: function( resp ){
console.log("getToken:failure");
console.log(resp);
}
})
);
}
/////////////////////////////////////////////////////////////////////////////////////////
function CreateWorkspace(ClientID , EntityID, wsName, groupId,accessType){
console.log("CreateWorkspace");
//debugger;
return $.when(
$.ajax({
url: cache["baseurl"] + 'workspaces',
type: 'post',
data: JSON.stringify({
database: "Blah",
custom1:ClientID ,
custom2:EntityID ,
default_security: "private", //change back to private
name: wsName
}),
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
cache[ "group_id" ] = groupId;
addGroup(resp.data.id, "workspaces", accessType);
cache[ "workspace_id" ] = resp.data.id;
console.log("CreateWorkspace:success");
},
failure: function( resp ){
console.log("CreateWorkspace:failure");
console.log(resp);
}
})
);
}
/////////////////////////////////////////////////////////////////////////////////////////
function AddFolderToWorkspace(fname,accessType,documentGroup ){
console.log("AddFolderToWorkspace");
//debugger;
return $.when(
$.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "workspace_id" ] + '/folders',
type: 'post',
data: JSON.stringify({
database:"Blah",
name:fname,
default_security:"inherit",
profile:
{
author:cache["user_id"],
class:"DOC",
comment:"",
custom29:documentGroup
}
}),
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
//cache[ "group_id" ] = ""; //remove
addGroup(resp.data.id, "folders", accessType);
cache[ "FolderIds"].push({"root":"","name":fname,id :resp.data.id});
console.log("AddFolderToWorkspace:success");
},
failure: function( resp ){
console.log("AddFolderToWorkspace:failure");
console.log(fname);
console.log(resp);
}
})
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
/*
access levels
"no_access", "read", "read_write", "full_access"
what are the possible values for user types?
"user" or "group"
*/
function addGroup(objectID, type, accessType){
//type documents, workspaces, folders
//debugger;
console.log("cache[ 'group_id'] " + cache[ "group_id" ] );
if(cache[ "group_id" ] !==""){
return $.when(
$.ajax({
url: cache["baseurl"] + type + '/' + objectID + "/security",
type: 'post',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
data: JSON.stringify({
include:
[{access_level: accessType,
id: cache[ "group_id" ],
type: "group"
}]
}),
success: function( resp ){
//debugger;
//user_type
// cache[ "doc_id" ] = resp.data[0].id;
console.log("addGroup:success");
},
failure: function( resp ){
//debugger;
console.log("addGroup:failure");
console.log(resp);
}
})
);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
function AddFolderToFolder(root, father, fname ,accessType,taxYear){
console.log("AddFolderToFolder");
console.log(father + "-" + fname);
//debugger;
return $.when(
$.ajax({
url: cache["baseurl"] +'workspaces/' + cache["FolderIds"].filter(function (el) {
return el.name == father && el.root == root;
})[0].id + '/folders',
type: 'post',
data: JSON.stringify({
database:"Blah",
name:fname,
default_security:"inherit",
profile:
{
author:cache["user_id"],
class:"DOC",
comment:"",
custom4:taxYear,
custom29:father
}
}),
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
addGroup(resp.data.id, "folders", accessType);
cache[ "FolderIds"].push({"root" : father, name:fname,id :resp.data.id});
console.log("AddFolderToFolder:success");
},
failure: function( resp ){
console.log("AddFolderToFolder:failure");
console.log(fname);
console.log(resp);
}
})
);
}
/////////////////////////////////////////////////////////////////////////////////////////
getToken()//ClientID , EntityID, wsName, groupId,accessType
.then(CreateWorkspace("11274","438917","test 2","Blah","read"), function(err) {console.log( err );})
.then(AddFolderToWorkspace("Billing","read","Billing"), function(err) {console.log( err );})
//root, father, fname ,accessType,taxYear
.then(AddFolderToFolder("","Billing","31-Dec-2017","full_access","2017"), function(err) {console.log( err );})
.then(AddFolderToFolder("","Billing","31-Dec-2016","full_access","2016"), function(err) {console.log( err );})
Wednesday, May 24, 2017
Create Search Folder In Imanage
//########################################################
function GetSearchFolder(SFId ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
// return d.name == WSName;
//});
//cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function GetWorkspace(WSName ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/search',// ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
return d.name == WSName;
});
cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id" ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
{
"custom4":TaxYear,
"container": stripped,
"databases":"Blah"
}
}),
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
//cache[ "folder_id" ] = resp.data.id;
console.log("CreateSearchFolder:success");
},
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
}
})
);
}
//########################################################
// implementation
//########################################################
getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017"))
function GetSearchFolder(SFId ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
// return d.name == WSName;
//});
//cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function GetWorkspace(WSName ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/search',// ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
return d.name == WSName;
});
cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id" ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
{
"custom4":TaxYear,
"container": stripped,
"databases":"Blah"
}
}),
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
//cache[ "folder_id" ] = resp.data.id;
console.log("CreateSearchFolder:success");
},
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
}
})
);
}
//########################################################
// implementation
//########################################################
getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017"))
loading jquery in dev tools
sorry I lost where I got this from for the HT
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
jQuery.noConflict();
Tuesday, May 23, 2017
wcf JSON deserialization
this
new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(results)
will not work with complex objects
you need to create objects
for example, this is the IManage Login JSON
new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(results)
will not work with complex objects
you need to create objects
for example, this is the IManage Login JSON
[DataContract]
public class IManageUser
{
[DataMember(Name = "email")]
public string email { get; set; }
[DataMember(Name = "full_name")]
public string full_name { get; set; }
[DataMember(Name = "user_id")]
public string user_id { get; set; }
}
[DataContract]
public class IManageLoginInfo
{
[DataMember(Name = "X-Auth-Token")]
public string X_Auth_Token { get; set; }
[DataMember(Name = "max_age")]
public int max_age { get; set; }
[DataMember(Name = "persona")]
public string persona { get; set; }
[DataMember(Name = "user")]
public IManageUser user { get; set; }
}
then you could do something like this:
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
results = sr.ReadToEnd();
sr.Close();
IManageLoginInfo info = null;
using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(results)))
{
DataContractJsonSerializer
serializer = new DataContractJsonSerializer(typeof(IManageLoginInfo));
info = (IManageLoginInfo)serializer.ReadObject(ms);
}
this.token =
info.X_Auth_Token;
Monday, May 22, 2017
“The underlying connection was closed: An unexpected error occurred on a send.” and bad certificate
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Friday, May 19, 2017
Create search folder in IManage API
//########################################################
function GetSearchFolder(SFId ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
// return d.name == WSName;
//});
//cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function GetWorkspace(WSName ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/search',// ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
return d.name == WSName;
});
cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id" ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
{
"custom4":TaxYear,
"container": stripped,
"databases":"Blah"
}
}),
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
//cache[ "folder_id" ] = resp.data.id;
console.log("CreateSearchFolder:success");
},
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
}
})
);
}
//########################################################
// implementation
//########################################################
getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017b"))
"databases" property is wierd
function GetSearchFolder(SFId ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'search-folders/' + SFId,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
//temp = $.grep(resp.data, function (d) {
// return d.name == WSName;
//});
//cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function GetWorkspace(WSName ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/search',// ?name=' + WSName,//until we get the indexer to work
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
temp = $.grep(resp.data, function (d) {
return d.name == WSName;
});
cache[ "ws_id" ] = temp[0].id ;
console.log("GetWorkspace:success");
},
failure: function( resp ){
console.log("GetWorkspace:failure");
console.log(resp);
}
})
);
}
//########################################################
function CreateSearchFolder(folderName, TaxYear ){
var stripped = cache[ "ws_id"].replace(/\D/g,'');
// return either the cached value or jqXHR object wrapped Promise
return $.when(
// cache[ "Token" ] ||
$.ajax({
url: cache["baseurl"] +'workspaces/' + cache[ "ws_id" ] + '/search-folders',
type: 'post',
data: JSON.stringify({
database: "Blah",
name: folderName,
default_security: "inherit",
searchprofile:
{
"custom4":TaxYear,
"container": stripped,
"databases":"Blah"
}
}),
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
//debugger;
//cache[ "folder_id" ] = resp.data.id;
console.log("CreateSearchFolder:success");
},
failure: function( resp ){
console.log("CreateSearchFolder:failure");
console.log(resp);
}
})
);
}
//########################################################
// implementation
//########################################################
getToken().then(GetWorkspace("Blah"))
.then(CreateSearchFolder("31-Dec-2017", "2017b"))
"databases" property is wierd
IManage code to add workspace to my matters
/////////////////////////////////////////////////////////////////////////////////////////////
function getWS(wsName ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
$.ajax({
url: cache["baseurl"] +'workspaces/search', //goto get the indexer to work - ?name=' +wsName,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
var temp = resp.data.filter(function(item) {
return item.name == wsName;
});
cache[ "ws_name" ] =wsName;
cache[ "ws_id" ] = temp[0].id;
console.log("getWS:success");
},
failure: function( resp ){
console.log("getWS:failure");
console.log(resp);
}
})
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
/*
access levels
"no_access", "read", "read_write", "full_access"
what are the possible values for user types?
"user" or "group"
*/
function addWSToMyMatters(){
return $.when(
$.ajax({
url: cache["baseurl"] + 'folders/my-matters/subfolders',
type: 'post',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
data: JSON.stringify({ "name":cache[ "ws_name" ],
"target":
{ "database":"Blah",
"id":cache[ "ws_id" ],
"subtype":"work",
"wstype":"workspace"}
}),
success: function( resp ){
debugger;
//user_type
// cache[ "doc_id" ] = resp.data[0].id;
console.log("addWSToMyMatters:success");
},
failure: function( resp ){
console.log("addWSToMyMatters:failure");
console.log(resp);
}
})
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
getToken().then(getWS("11Blah)"))
.then(addWSToMyMatters());
function getWS(wsName ){
// return either the cached value or jqXHR object wrapped Promise
return $.when(
$.ajax({
url: cache["baseurl"] +'workspaces/search', //goto get the indexer to work - ?name=' +wsName,
type: 'get',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
success: function( resp ){
debugger;
var temp = resp.data.filter(function(item) {
return item.name == wsName;
});
cache[ "ws_name" ] =wsName;
cache[ "ws_id" ] = temp[0].id;
console.log("getWS:success");
},
failure: function( resp ){
console.log("getWS:failure");
console.log(resp);
}
})
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
/*
access levels
"no_access", "read", "read_write", "full_access"
what are the possible values for user types?
"user" or "group"
*/
function addWSToMyMatters(){
return $.when(
$.ajax({
url: cache["baseurl"] + 'folders/my-matters/subfolders',
type: 'post',
headers: {
'X-Auth-Token':cache[ "Token" ],
'Content-Type': 'application/json'
},
dataType: 'json',
data: JSON.stringify({ "name":cache[ "ws_name" ],
"target":
{ "database":"Blah",
"id":cache[ "ws_id" ],
"subtype":"work",
"wstype":"workspace"}
}),
success: function( resp ){
debugger;
//user_type
// cache[ "doc_id" ] = resp.data[0].id;
console.log("addWSToMyMatters:success");
},
failure: function( resp ){
console.log("addWSToMyMatters:failure");
console.log(resp);
}
})
);
}
/////////////////////////////////////////////////////////////////////////////////////////////
getToken().then(getWS("11Blah)"))
.then(addWSToMyMatters());
Subscribe to:
Comments (Atom)