Access Rights for Person Report

This is an example of an Access Rights for Person Report that is filtered by the instance you are interested in, the Person you are interested in, and the event type(s) (Access Granted and Access Denied events). To filter on Dates as well look at the example above for active cards. The Curl snippet expect that you already know the keys for your instance, and event type you wish to filter for.

Example in C#

var currentInstance  = await client.GetCurrentInstanceAsync();
var app = (await client.GetAppsAsync(currentInstance)).Where(a=> a.ApiKey == "MercuryService").FirstOrDefault(); 
var eventAccessDeniedKey = (await client.GetEventTypesAsync(app)).Where(a=> a.CommonName == "Access Denied").FirstOrDefault()?.Key;
var eventAccessGrantedKey = (await client.GetEventTypesAsync(app)).Where(a=> a.CommonName == "Access Granted").FirstOrDefault()?.Key;
var personKey = (await client.GetPersonByEmailAsync(currentInstance, "rusty.rusteze@Rusteze.com")).Key;

var operations = 
	new BsonDocument[] 
	{ 
	    new BsonDocument("$match", 
	    new BsonDocument("$or", 
	    new BsonArray
	            {
	                new BsonDocument("ObjectLinks.LinkedObjectId", 
	                new ObjectId(eventAccessDeniedKey)),
	                new BsonDocument("ObjectLinks.LinkedObjectId", 
	                new ObjectId(eventAccessGrantedKey))
	            })),
	    new BsonDocument("$match", 
	    new BsonDocument("InFolderId", 
	    new ObjectId(currentInstance.Key))),
	    new BsonDocument("$unwind", 
	    new BsonDocument("path", "$ObjectLinks")),
	    new BsonDocument("$match", 
    new BsonDocument("$and", 
    new BsonArray
            {
                new BsonDocument("ObjectLinks.Relation", "Person"),
                new BsonDocument("ObjectLinks.LinkedObjectId", 
                new ObjectId("5b7195f692dacd0ca49718b0"))
            })),
	    new BsonDocument("$sort", 
	    new BsonDocument("OccurredOn", -1)),
	    new BsonDocument("$project", 
	    new BsonDocument
	        {
	            { "_id", 1 }, 
	            { "MessageLong", 1 }, 
	            { "ObjectLinks.LinkedObjectId", 1 }, 
	            { "ObjectLinks.Relation", 1 }, 
	            { "OccurredOn", 1 }, 
	            { "EventData.Reader", 1 }, 
	            { "EventData.EncodedCardNumber", 1 }
	        })
	};

var AccessRights = await client.AggregateAsync(currentInstance, "Events", operations);

Example in CURL

curl -X POST \
  'https://keepapi.feenicshosting.com/api/f/INSTANCE_KEY_HERE/aggregate/Events?queryTimeout=30&jsonStrict=False%20' \
  -H 'Accept: */*' \
  -H 'Authorization: Bearer TOKEN_GOES_HERE' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Host: keepapi.feenicshosting.com' \
  -H 'accept-encoding: gzip, deflate' \
  -H 'cache-control: no-cache' \
  -H 'content-length: 724' \
  -d '[
        "{ 
            \"$match\" : 
            { 
                \"$or\" : 
                [
                    { \"ObjectLinks.LinkedObjectId\" : ObjectId(\"EVENT_ACCESS_GRANTED_KEY\") },
                    { \"ObjectLinks.LinkedObjectId\" : ObjectId(\"EVENT_ACCESS_DENIED_KEY\") }
                ] 
            } 
        }","
        { 
            \"$match\" : { \"InFolderId\" : ObjectId(\"INSTANCE_KEY_HERE\") } 
        }","
        { 
            \"$unwind\" : { \"path\" : \"$ObjectLinks\" } 
        }","
        { 
            \"$match\" : 
            { 
                \"$and\" : 
                [
                    { \"ObjectLinks.Relation\" : \"Person\" }, 
                    { \"ObjectLinks.LinkedObjectId\" : ObjectId(\"KEY_OF_PERSON\") }
                ] 
            } 
        }","
        { 
            \"$sort\" : { \"OccurredOn\" : -1 } 
        }","
        { 
            \"$project\" : 
            { 
                \"_id\" : 1,
                \"MessageLong\" : 1,
                \"ObjectLinks.LinkedObjectId\" : 1, 
                \"ObjectLinks.Relation\" : 1, 
                \"OccurredOn\" : 1, 
                \"EventData.Reader\" : 1, 
                \"EventData.EncodedCardNumber\" : 1 
            } 
        }"
    ]'

Example Of Aggregate Used in JSON

[
        { 
            "$match" : 
            { 
                "$or" : 
                [
                    { "ObjectLinks.LinkedObjectId" : ObjectId("EVENT_ACCESS_DENIED_KEY") },
                    { "ObjectLinks.LinkedObjectId" : ObjectId("EVENT_ACCESS_DENIED_KEY") }
                ] 
            } 
        },
        { 
            "$match" : { "InFolderId" : ObjectId("INSTANCE_KEY_HERE") } 
        },
        { 
            "$unwind" : { "path" : "$ObjectLinks" } 
        },
        { 
            "$match" : 
            { 
                "$and" : 
                [
                    { "ObjectLinks.Relation" : "Person" }, 
                    { "ObjectLinks.LinkedObjectId" : ObjectId("KEY_OF_PERSON") }
                ] 
            } 
        },
        { 
            "$sort" : { "OccurredOn" : -1 } 
        },
        { 
            "$project" : 
            { 
                "_id" : 1,
                "MessageLong" : 1,
                "ObjectLinks.LinkedObjectId" : 1, 
                "ObjectLinks.Relation" : 1, 
                "OccurredOn" : 1, 
                "EventData.Reader" : 1, 
                "EventData.EncodedCardNumber" : 1 
            } 
        }
    ]