All Cards by Access Level Report

This generates an item for each card and its corresponding access level between specified dates. This does not include cards on Attendee objects (Visitor Management).

Example in C#

var currentInstance  = await client.GetCurrentInstanceAsync();

var match1 = new BsonDocument("$match", 
    new BsonDocument("_t", "Person"));
	
var unwind1 = new BsonDocument("$unwind", 
    new BsonDocument
        {
            { "path", "$CardAssignments" }, 
            { "preserveNullAndEmptyArrays", false }
        });
		
var match2 = new BsonDocument("$match", 
    new BsonDocument
        {
            { "CardAssignments.ExpiresOn", 
    			new BsonDocument
            	{
                	{ "$gte", DateTime.UtcNow }, 
                	{ "$lte",  DateTime.UtcNow.AddYears(25) }
            	} 
				}, 
            { "ObjectLinks.Relation", "AccessLevel" }
        });
var unwind2 = new BsonDocument("$unwind", 
    new BsonDocument
        {
            { "path", "$ObjectLinks" }, 
            { "preserveNullAndEmptyArrays", false }
        });
var project = new BsonDocument("$project", 
    new BsonDocument
        {
            { "CardAssignments", 1 }, 
            { "_id", 0 }, 
            { "ObjectLinks.CommonName", 1 }
        });


var AllCardsByAccessLevel = await client.AggregateAsync(currentInstance, "KeepObjects", new[] {match1,unwind1,unwind2, match2, project}, 30);

Example in CURL

curl -X POST \
  'https://keepapi.feenicshosting.com/api/f/INSTANCE_KEY_HERE/aggregate/KeepObjects?queryTimeout=30&jsonStrict=False%20' \
  -H 'Authorization: Bearer TOKEN_GOES_HERE' \
  -H 'Content-Type: application/json' \
  -d '["
        { \"$match\" : { \"_t\" : \"Person\" } }","
        { \"$unwind\" : { \"path\" : \"$CardAssignments\", \"preserveNullAndEmptyArrays\" : false } }","
        { \"$unwind\" : { \"path\" : \"$ObjectLinks\", \"preserveNullAndEmptyArrays\" : false } }","
        { \"$match\" : 
            { \"CardAssignments.ExpiresOn\" : 
                { 
                    \"$gte\" : ISODate(\"2019-06-12T18:50:07.264Z\"),
                    \"$lte\" : ISODate(\"2044-06-12T18:50:07.264Z\") 
                }, 
                \"ObjectLinks.Relation\" : \"AccessLevel\" }
        }","
        { 
            \"$project\" : 
            { 
                \"CardAssignments\" : 1, 
                \"_id\" : 0, 
                \"ObjectLinks.CommonName\" : 1 
            } 
        }"
    ]'

Example Of Aggregate Used in JSON

[
    { "$match" : { "_t" : "Person" } },
    { "$unwind" : { "path" : "$CardAssignments", "preserveNullAndEmptyArrays" : false } },
    { "$unwind" : { "path" : "$ObjectLinks", "preserveNullAndEmptyArrays" : false } },
    { "$match" : 
        { "CardAssignments.ExpiresOn" : 
            { 
                "$gte" : ISODate("2019-06-12T18:50:07.264Z"),
                "$lte" : ISODate("2044-06-12T18:50:07.264Z") 
            }, 
            "ObjectLinks.Relation" : "AccessLevel" }
    },
    { 
        "$project" : 
        { 
            "CardAssignments" : 1, 
            "_id" : 0, 
            "ObjectLinks.CommonName" : 1 
        } 
    }
]

All Cards Per Access Level Report

This Groups all cards on Person Objects into an array under their specific access level, between specified dates. This does not include cards on Attendee objects (Visitor Management).

Example in C#

var currentInstance  = await client.GetCurrentInstanceAsync();

var match1 = new BsonDocument("$match", 
    new BsonDocument("_t", "Person"));
	
var unwind1 = new BsonDocument("$unwind", 
    new BsonDocument
        {
            { "path", "$CardAssignments" }, 
            { "preserveNullAndEmptyArrays", false }
        });
var unwind2 =  new BsonDocument("$unwind", 
    new BsonDocument
        {
            { "path", "$ObjectLinks" }, 
            { "preserveNullAndEmptyArrays", false }
        });
		
var match2 = new BsonDocument("$match", 
    new BsonDocument
        {
            { "CardAssignments.ExpiresOn", 
    		new BsonDocument
            	{
                	{ "$gte", DateTime.UtcNow }, 
                	{ "$lte",  DateTime.UtcNow.AddYears(25) }
            	} 
				}, 
            { "ObjectLinks.Relation", "AccessLevel" }
        });
var group = new BsonDocument("$group", 
			    new BsonDocument
		        {
		            { "_id", "$ObjectLinks.CommonName" }, 
		            { "CardAssignments", new BsonDocument("$push", "$CardAssignments") }
		        });

var AllCardsPerAccessLevel = await client.AggregateAsync(currentInstance, "KeepObjects", new[] {match1,unwind1,unwind2, match2, group}, 30);

Example in CURL

curl -X POST \
  'https://keepapi.feenicshosting.com/api/f/INSTANCE_KEY_HERE/aggregate/KeepObjects?queryTimeout=30&jsonStrict=False%20' \
  -H 'Authorization: Bearer TOKEN_GOES_HERE' \
  -H 'Content-Type: application/json' \
  -d '["
        { \"$match\" : { \"_t\" : \"Person\" } }","
        { \"$unwind\" : { \"path\" : \"$CardAssignments\", \"preserveNullAndEmptyArrays\" : false } }","
        { \"$unwind\" : { \"path\" : \"$ObjectLinks\", \"preserveNullAndEmptyArrays\" : false } }","
        { \"$match\" : 
            { 
                \"CardAssignments.ExpiresOn\" : 
                { 
                    \"$gte\" : ISODate(\"2019-06-12T18:54:27.586Z\"),
                    \"$lte\" : ISODate(\"2044-06-12T18:54:27.586Z\") 
                }, 
                \"ObjectLinks.Relation\" : \"AccessLevel\" }
        }","
        { 
            \"$group\" : 
            { 
                \"_id\" : \"$ObjectLinks.CommonName\",
                \"CardAssignments\" : { \"$push\" : \"$CardAssignments\" } 
            } 
        }"
    ]'

Example Of Aggregate Used in JSON

[
    { "$match" : { "_t" : "Person" } },
    { "$unwind" : { "path" : "$CardAssignments", "preserveNullAndEmptyArrays" : false } },
    { "$unwind" : { "path" : "$ObjectLinks", "preserveNullAndEmptyArrays" : false } },
    { "$match" : 
        { 
            "CardAssignments.ExpiresOn" : 
            { 
                "$gte" : ISODate("2019-06-12T18:54:27.586Z"),
                "$lte" : ISODate("2044-06-12T18:54:27.586Z") 
            }, 
            "ObjectLinks.Relation" : "AccessLevel" }
    },
    { 
        "$group" : 
        { 
            "_id" : "$ObjectLinks.CommonName",
            "CardAssignments" : { "$push" : "$CardAssignments" } 
        } 
    }
]