Access Rights for Reader Report

This is an example of an Access Rights for Reader Report that is filtered by the instance you are interested in, the Reader (mercury or engage) 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. Note the second Or for the reader filter is not needed in the match stage if you only want one reader. The purpose was to show that if you have the id whether it was an engage reader or not should not matter. For engage types you will need to add the engage events to the aggregate match filter.

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 mercuryReaderKey = (await client.GetMercuryReadersAsync(currentInstance)).Where(a=> a.CommonName == "MercuryReader").FirstOrDefault()?.Key;
var engageReaderKey = (await client.GetEngageReadersAsync(currentInstance)).Where(a=> a.CommonName == "EngageReader").FirstOrDefault()?.Key;

var operations = 
	new BsonDocument[] 
	{ 
	 	new BsonDocument 
		( "$match", new BsonDocument 
				( "$and", new BsonArray 
						{ 
							new BsonDocument("InFolderId", ObjectId.Parse(currentInstance.Key)),
							new BsonDocument 
							( 
								"$or", new BsonArray 
								{ 
									new BsonDocument ("ObjectLinks.LinkedObjectId", ObjectId.Parse(eventAccessGrantedKey??"000000000000000000000000") ),
									new BsonDocument ("ObjectLinks.LinkedObjectId", ObjectId.Parse(eventAccessDeniedKey??"000000000000000000000000"))
								} 
							),
							new BsonDocument 
							( 		
								"$or", new BsonArray 
								{ 
									new BsonDocument ("ObjectLinks.LinkedObjectId", ObjectId.Parse(mercuryReaderKey??"000000000000000000000000")),
									new BsonDocument ("ObjectLinks.LinkedObjectId", ObjectId.Parse(engageReaderKey??"000000000000000000000000"))
								}  
							) 
						} 
					)
			),
	    new BsonDocument("$unwind", 
	    new BsonDocument("path", "$ObjectLinks")),
	    new BsonDocument("$match", new BsonDocument("ObjectLinks.Relation", "Person")),
	    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.Person", 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: 825' \
  -d '["
        { 
            \"$match\" : 
            { 
                \"$and\" : 
                [
                    { \"InFolderId\" : ObjectId(\"INSTANCE_KEY_HERE\") },
                    { 
                        \"$or\" : 
                        [
                            { \"ObjectLinks.LinkedObjectId\" : ObjectId(\"EVENT_ACCESS_GRANTED_KEY\") },
                            { \"ObjectLinks.LinkedObjectId\" : ObjectId(\"EVENT_ACCESS_DENIED_KEY\") }
                        ] 
                    }, 
                    { 
                        \"$or\" : 
                        [
                            { \"ObjectLinks.LinkedObjectId\" : ObjectId(\"MERCURY_READER_KEY\") },
                            { \"ObjectLinks.LinkedObjectId\" : ObjectId(\"ENGAGE_READER_KEY\") }
                        ] 
                    }
                ] 
            } 
        }","
        { \"$unwind\" : { \"path\" : \"$ObjectLinks\" } }","
        { \"$match\" : { \"ObjectLinks.Relation\" : \"Person\" } }","
        { \"$sort\" : { \"OccurredOn\" : -1 } }","
        { 
            \"$project\" : 
            { 
                \"_id\" : 1,
                \"MessageLong\" : 1, 
                \"ObjectLinks.LinkedObjectId\" : 1, 
                \"ObjectLinks.Relation\" : 1, 
                \"OccurredOn\" : 1, 
                \"EventData.Reader\" : 1, 
                \"EventData.Person\" : 1, 
                \"EventData.EncodedCardNumber\" : 1 
            } 
        }"
    ]'

Example Of Aggregate Used in JSON

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