Adding Multiple People via Batch

Now that we are amazing at adding one employee or person at a time lets figure out how to add many. It is basically the same as adding one person except we use an array of PersonInfo objects instead of just a PersonInfo object. In the example we are adding three people into the system by explicitly typing them out and arranging them into an array. For your purposes it will probably be best to read in a .csv file and compile an array as shown in the second part of the example. Another tip is to separate the Person array, if the person array is large, and submit it in multiple batches just in case there is an error in one person item you wont have to re-upload the whole array, just the portion that failed.

Everything that a PersonInfo can contain can be added here in the array, for a more content heavy example of adding information to a person please review the single person add.

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

Example in C#

var numOfPeople = await client.AddPeopleBatchAsync(currentInstance, new PersonInfo[]
{
    new PersonInfo
    {
        CommonName = "JaneDoe",
        GivenName = "Jane",
        Surname = "Doe",
        Addresses = new AddressInfo[]{ //address is an array of options
    				new PhoneInfo {Number = "847-691-0602", Type = "Work"},  
    				new EmailAddressInfo {MailTo = "work@email.com", Type = "Work"}, //email address with Type
    				new MailingAddressInfo {Street = "101 Champagne Ave", City = "Ottawa", Province = "ON", Country = "CA", PostalCode = "K1S4P3", Type = "Home"}
    		}        
    },
    new PersonInfo
    {
        CommonName = "BobSmith",
        GivenName = "Bob",
        Surname = "Smith",
        Addresses = new AddressInfo[]{ //address is an array of options
    				new PhoneInfo {Number = "847-691-0602", Type = "Work"},  
    				new EmailAddressInfo {MailTo = "work@email.com", Type = "Work"}, //email address with Type
    				new MailingAddressInfo {Street = "101 Champagne Ave", City = "Ottawa", Province = "ON", Country = "CA", PostalCode = "K1S4P3", Type = "Home"}
    		}           
    },
    new PersonInfo
    {
        CommonName = "JillSmith",
        GivenName = "Jill",
        Surname = "Smith",
        Addresses = new AddressInfo[]{ //address is an array of options
    				new PhoneInfo {Number = "847-691-0602", Type = "Work"},  
    				new EmailAddressInfo {MailTo = "work@email.com", Type = "Work"}, //email address with Type
    				new MailingAddressInfo {Street = "101 Champagne Ave", City = "Ottawa", Province = "ON", Country = "CA", PostalCode = "K1S4P3", Type = "Home"}
    		}           
    }
});

Example in CURL

curl -X POST \
  https://keepapi.feenicshosting.com/api/f/INSTANCE.KEY/people/complex \
  -H 'Authorization:  Bearer TOKEN_GOES_HERE' \
  -H 'Content-Type: application/json' \
  -d '{
    "$type": "Feenics.Keep.WebApi.Model.PersonInfo, Feenics.Keep.WebApi.Model",
    "GivenName": "cURL",
    "Surname": "Example1",
    "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.EmailAddressInfo, Feenics.Keep.WebApi.Model",
        "MailTo": "work@email.com",
        "Key": null,
        "IsPrivate": false,
        "Type": "Work",
        "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": null,
    "Key": null,
    "CommonName": "cURLExample1",
    "InFolderHref": null,
    "InFolderKey": null,
    "Links": [],
    "ObjectLinks": null,
    "Metadata": null,
    "Notes": null,
    "Tags": null,
    "Monikers": [
      {
        "$type": "Feenics.Keep.WebApi.Model.MonikerItem, Feenics.Keep.WebApi.Model",
        "Namespace": "AwsomePeople",
        "Nickname": "cURLExample1"
      }
    ],
    "Href": null
  },
  {
    "$type": "Feenics.Keep.WebApi.Model.PersonInfo, Feenics.Keep.WebApi.Model",
    "GivenName": "cURL",
    "Surname": "Example2",
    "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.EmailAddressInfo, Feenics.Keep.WebApi.Model",
        "MailTo": "work@email.com",
        "Key": null,
        "IsPrivate": false,
        "Type": "Work",
        "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": null,
    "Key": null,
    "CommonName": "cURLExample2",
    "InFolderHref": null,
    "InFolderKey": null,
    "Links": [],
    "ObjectLinks": null,
    "Metadata": null,
    "Notes": null,
    "Tags": null,
    "Monikers": [
      {
        "$type": "Feenics.Keep.WebApi.Model.MonikerItem, Feenics.Keep.WebApi.Model",
        "Namespace": "AwsomePeople",
        "Nickname": "cURLExample2"
      }
    ],
    "Href": null
  },
  {
    "$type": "Feenics.Keep.WebApi.Model.PersonInfo, Feenics.Keep.WebApi.Model",
    "GivenName": "cURL",
    "Surname": "Example3",
    "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.EmailAddressInfo, Feenics.Keep.WebApi.Model",
        "MailTo": "work@email.com",
        "Key": null,
        "IsPrivate": false,
        "Type": "Work",
        "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": null,
    "Key": null,
    "CommonName": "cURLExample3",
    "InFolderHref": null,
    "InFolderKey": null,
    "Links": [],
    "ObjectLinks": null,
    "Metadata": null,
    "Notes": null,
    "Tags": null,
    "Monikers": [
      {
        "$type": "Feenics.Keep.WebApi.Model.MonikerItem, Feenics.Keep.WebApi.Model",
        "Namespace": "AwsomePeople",
        "Nickname": "cURLExample3"
      }
    ],
    "Href": null
  }'
//Example Read From a File Makes an array of people
using (var reader = File.OpenText(@"c:\Random.csv"))
{
	var csv = new CsvReader(reader);
    //This assumes you know which fields are in the .csv you can create something more dynamic
    //This is just a simple example
	var people = csv.GetRecords<row>().Select(r => new PersonInfo
	{
		CommonName = $"{r.first_name} {r.last_name}",
		GivenName = r.first_name,
		Surname = r.last_name,
		Addresses = new AddressInfo[]{
			new EmailAddressInfo { Type = "Work", MailTo = r.work_email },
			new EmailAddressInfo { Type = "Home", MailTo = r.home_email },
			new PhoneInfo { Type = "Work", Number = r.phone1 },
			new PhoneInfo { Type = "Mobile", Number = r.phone2 },
			new PhoneInfo { Type = "Home", Number = r.phone3 },
			new MailingAddressInfo { Type = "Home", Street = r.address, City = r.city, Province = r.state, Country = "USA", PostalCode = r.zip }
			}

	}).ToArray();
	//still need to add the people
	numOfPeople = await client.AddPeopleBatchAsync(currentInstance, people);
}
class row
{
	public string first_name { get; set; }
	public string last_name { get; set; }
//	public string compan_name { get; set; }
	public string address { get; set; }
	public string city { get; set; }
	public string state { get; set; }
	public string zip { get; set; }
	public string phone1 { get; set; }
	public string phone2 { get; set; }
	public string phone3 { get; set; }
	public string work_email { get; set; }
	public string home_email { get; set; }
}