Adding a new Person

Now let us look at adding one employee or person at a time. A person is added to a folder. If Badges and/or Access Levels are ready to be added like ours are then there are a couple of ways to do that. You can either add them during the creation of the person as an Object Link or after using separate calls. A Card Assignment can also be added to a person much the same way as an AccessLevel except it has its own property in the PersonInfo object and thus should be added to that, either during creation or after it.

If you have custom form data for a person you can also add that here as Metadata(same procedure as Object Links except for Metadata and MetadataItem), be sure that the custom form is set up in Keep first.

For more information on People and the methods used please look at PersonInfo.

Example in C#

//Everything that can be added to a person
var person = await client.AddPersonAsync(currentInstance, new PersonInfo
{
    CommonName = "JohnDoe", //Should be unique but system will generate unique keys so it is possible to duplicate
    GivenName = "John",
    Surname = "Doe",
    Addresses = new AddressInfo[]
    {
                new PhoneInfo {Number = "847-691-0602", Type = "Work"}, //phone number with type
                new PhoneInfo {Number = "847-764-8989", Type = "Home"}, //phone number with type
                new PhoneInfo {Number = "847-999-2222", Type = "Mobile"}, //phone number with type
                new EmailAddressInfo {MailTo = "work@email.com", Type = "Work"}, //email address with Type
                new EmailAddressInfo {MailTo = "home@email.com", Type = "Home"}, //email address with Type
                new MailingAddressInfo {Street = "101 Champagne Ave", City = "Ottawa", Province = "ON", Country = "CA", PostalCode = "K1S4P3", Type = "Home"}
    },
    ObjectLinks = new ObjectLinkItem[]
    {//object links are stored in an array
        new ObjectLinkItem {CommonName = accessLevel.CommonName, Href = accessLevel.Href, LinkedObjectKey = accessLevel.Key},
        new ObjectLinkItem {CommonName = badgeType.CommonName, Href = badgeType.Href, LinkedObjectKey = badgeType.Key}
    },
    CardAssignments = new CardAssignmentInfo[]
    {
        new CardAssignmentInfo
        {
            AntiPassbackExempt = false,
            DisplayCardNumber = "654",//You need to know the card number and/or generate it depends if the card is new or used.
            EncodedCardNumber = 654,//The Display number does not have to match but it is a good thing to do for simplicity
            ActiveOn = DateTime.UtcNow, //today's date
            ExpiresOn = DateTime.UtcNow.AddYears(1), //one year into the future
            ExtendedAccess = false
        }
    },
    Links = new List<Link>
    {
        new Link
        {
            Anchor = new Anchor {Href = "Href of the linked item here",Text = "This is usually set by the system (what is the link)" },
            Relation = "The Relation"
        }
    },
    Metadata = new MetadataItem[]
    {
        new MetadataItem { Application = "AppName", Values = "The Information should store as JSON here" }
    },
    Monikers = new MonikerItem[]
    {
        new MonikerItem { Namespace =  "AwsomePeople" , Nickname = "TheBob" }
    },
    Notes = new NoteInfo[]
    {
        new NoteInfo
        {
            CreatedOn = DateTime.UtcNow,
            NoteText = "This is the note!",
            User = new ObjectLinkItem
            {
                CommonName = $"{(await client.GetCurrentUserAsync()).CommonName}ThatSetTheNote",
                LinkedObjectKey = ((await client.GetCurrentUserAsync()).Key),
                MetaDataBson = default(byte[]),
                Relation = "The user that set the note"
            }
        }
    },
    Tags = new string[]{"array","of", "tags"}
});
await client.SetAccessLevelForPersonAsync(person, accessLevel);

Example in CURL

#Create Person
curl -X POST \
  https://keepapi.feenicshosting.com/api/f/INSTANCE.KEY/people \
  -H 'Authorization: Bearer TOKEN_GOES_HERE' \
  -H 'Content-Type: application/json' \
  -d '{"$type":"Feenics.Keep.WebApi.Model.PersonInfo, Feenics.Keep.WebApi.Model","GivenName":"John","Surname":"Doe","Addresses":[{"$type":"Feenics.Keep.WebApi.Model.PhoneInfo, Feenics.Keep.WebApi.Model","Number":"847-691-0602","Key":null,"IsPrivate":false,"Type":"Work","Href":null},{"$type":"Feenics.Keep.WebApi.Model.PhoneInfo, Feenics.Keep.WebApi.Model","Number":"847-764-8989","Key":null,"IsPrivate":false,"Type":"Home","Href":null},{"$type":"Feenics.Keep.WebApi.Model.PhoneInfo, Feenics.Keep.WebApi.Model","Number":"847-999-2222","Key":null,"IsPrivate":false,"Type":"Mobile","Href":null},{"$type":"Feenics.Keep.WebApi.Model.EmailAddressInfo, Feenics.Keep.WebApi.Model","MailTo":"work@email.com","Key":null,"IsPrivate":false,"Type":"Work","Href":null},{"$type":"Feenics.Keep.WebApi.Model.EmailAddressInfo, Feenics.Keep.WebApi.Model","MailTo":"home@email.com","Key":null,"IsPrivate":false,"Type":"Home","Href":null},{"$type":"Feenics.Keep.WebApi.Model.MailingAddressInfo, Feenics.Keep.WebApi.Model","Street":"101 Champagne Ave","City":"Ottawa","Province":"ON","Country":"CA","PostalCode":"K1S4P3","Key":null,"IsPrivate":false,"Type":"Home","Href":null}],"CardAssignments":[{"$type":"Feenics.Keep.WebApi.Model.CardAssignmentInfo, Feenics.Keep.WebApi.Model","Key":null,"EncodedCardNumber":6564212356,"DisplayCardNumber":"6564212356","ActiveOn":"2019-01-23T16:57:26.1725827Z","ExpiresOn":"2020-01-23T16:57:26.1725827Z","PinCode":null,"AntiPassbackExempt":false,"ExtendedAccess":false,"PinExempt":false,"IsDisabled":false,"ManagerLevel":0,"OriginalUseCount":null,"CurrentUseCount":0,"Note":null,"HexValue":null,"RecordId":null,"Href":null}],"Key":null,"CommonName":"JohnDoe","InFolderHref":null,"InFolderKey":null,"Links":[{"$type":"Feenics.Keep.WebApi.Model.Link, Feenics.Keep.WebApi.Model","Relation":"The Relation","Anchor":{"$type":"Feenics.Keep.WebApi.Model.Anchor, Feenics.Keep.WebApi.Model","Href":"/api/f/5b61d62492dacd062c424424/accesslevels/5b717f9192dacd0e8c2cfbaf","Text":"This is usually set by the system (what is the link)"}}],"ObjectLinks":[{"$type":"Feenics.Keep.WebApi.Model.ObjectLinkItem, Feenics.Keep.WebApi.Model","Href":"/api/f/5b61d62492dacd062c424424/accesslevels/5b717f9192dacd0e8c2cfbaf","LinkedObjectKey":"5b717f9192dacd0e8c2cfbaf","CommonName":"StandardAccessLevel","Relation":"AccessLevel","MetaDataBson":null},{"$type":"Feenics.Keep.WebApi.Model.ObjectLinkItem, Feenics.Keep.WebApi.Model","Href":"/api/f/5b61d62492dacd062c424424/badgetypes/5beb38fe92dacd0cfc998eb6","LinkedObjectKey":"5beb38fe92dacd0cfc998eb6","CommonName":"Security","Relation":"BadgeType","MetaDataBson":null}],"Metadata":[{"$type":"Feenics.Keep.WebApi.Model.MetadataItem, Feenics.Keep.WebApi.Model","Application":"AppName","Values":"THIS_IS_A_JSON_STRING"}],"Notes":[{"$type":"Feenics.Keep.WebApi.Model.NoteInfo, Feenics.Keep.WebApi.Model","Key":null,"CreatedOn":"2019-01-23T16:57:26.1725827Z","User":{"$type":"Feenics.Keep.WebApi.Model.ObjectLinkItem, Feenics.Keep.WebApi.Model","Href":null,"LinkedObjectKey":"5b7195f792dacd0ca49718b2","CommonName":"deverThatSetTheNote","Relation":"The user that set the note","MetaDataBson":null},"NoteText":"This is the note!","Href":null}],"Tags":["array","of","tags"],"Monikers":[{"$type":"Feenics.Keep.WebApi.Model.MonikerItem, Feenics.Keep.WebApi.Model","Namespace":"AwsomePeople","Nickname":"TheUniquePerson"}],"Href":null}'
#Set Access Level
curl -X PUT \
  https://keepapi.feenicshosting.com/api/f/INSTANCE.KEY/people/PERSON.KEY/accesslevels \
  -H 'Authorization: Bearer TOKEN_GOES_HERE'