Update/Solution
There isn't a way to add a photo to a person object on creating a contact via People API. However you can updated the photo directly after using People.People.updateContactPhoto. updateContactPhoto has a limit of 60 queries per minute per user. If your script needs to update more than 60 contact photos, then you will need to add a delay in your code so that query limit isn't reached
Question:
I am creating a large list of contacts from a set of data, including contact photos for each contact. When I create contacts via people.createContact, if I have the photos field there it states "person.photos is a read only field." How I can I create the contact with a profile photo link as well?
Example Code
const contact = {names:..., addresses:..., emailAddressess:..., phoneNumbers:...,
photos: {"url":..., "primary": true}
}
People.People.createContact(contact)
Update 1: Currently this is what I'm doing and it works. The main problem now is I don't want to use the Utilities.Sleep function. I'm looping over this function hundreds of times, and that adds up quickly. If I don't use the sleep though around the 40th or 50th contact it throws an "Internal error encountered". The contact it errors on is different each time, so the error is not tied to a specific person. My assumption is the error comes from running too many requests too quickly, but how can I run this without forcing it to sleep?
function importPerson(person){
const photoData = encodePhotoData(person.photos[0].url)
delete person.photos
const newContact = People.People.createContact(person)
People.People.updateContactPhoto({
photoBytes: photoData,
},newContact.resourceName)
//This stops it from throwing an error
Utilities.sleep(1000)
}