$client->calendar
Every method in this namespace: its signature, its parameters, what it returns and an example.
Methods
Calendar events found in mail or put on the calendar here, expanded into occurrences, with invitations, changes, cancellations and answers sent by email.
calendar->listEventscalendar->listAllEventscalendar->iterateEventscalendar->getEventcalendar->getEventIcscalendar->createEventcalendar->updateEventcalendar->deleteEventcalendar->cancelEventcalendar->respondToEventcalendar->declineProposalcalendar->hideEventcalendar->unhideEventcalendar->freeBusycalendar->listFeedscalendar->createFeedcalendar->resetFeedcalendar->deleteFeedcalendar->listSubscriptionscalendar->createSubscriptioncalendar->updateSubscriptioncalendar->refreshSubscriptioncalendar->deleteSubscriptioncalendar->importIcscalendar->listImportscalendar->listAllImportscalendar->iterateImportscalendar->getImportcalendar->undoImport
calendar->listEvents
List one page of event occurrences inside a time window
listEvents( DateTimeInterface|string $from, DateTimeInterface|string $to, ?string $timezone = null, ?bool $includeTeam = null, ?string $q = null, ?int $limit = null, ?string $cursor = null, ?string $apiKey = null,): PageExpands your events into their occurrences between from and to and returns one page of them, sorted by start time and then by event id. A recurring series gives one row per instance in the window, with its excluded dates left out, and every row points back to its event through eventId. The window is required because a repeating series has no end to list up to. Follow nextCursor while hasMore is true, with the same from, to and timezone:, to read every occurrence, or let listAllEvents and iterateEvents do that walk.
to must be after from and at most 366 days later. A missing from or to is a 422 invalid_parameter, while a value that does not parse, a reversed or overlong window, or an unknown zone is a 400 invalid_parameter naming the field. Both bounds take a DateTimeInterface or an ISO 8601 string, and the SDK sends a DateTimeInterface as an ISO 8601 instant in UTC.
timezone is an IANA zone and defaults to UTC on the server. It is used to expand any event stored without a zone of its own, which is what decides the day an all day event lands on.
Parameters
fromstring|DateTimeInterfaceRequiredStart of the window.
tostring|DateTimeInterfaceRequiredEnd of the window, after
fromand at most 366 days later.timezonestringIANA zone such as
Europe/London, at most 64 characters. Defaults toUTC.includeTeambooltrueadds the events of the rest of the workspace, apart from the ones marked private. Only a key of the workspace owner sees more with it. Defaults tofalse.qstringWords to look for in the title, the place and the organiser, at most 200 characters. Only events that hold every word come back, so pass a long window to find an event by name.
limitintOccurrences per page, a whole number from 1 to 100. The server defaults to 25.
cursorstringThe
nextCursorof the previous page, sent with the same window. It is opaque, so never build one yourself.apiKeystringOverrides the client's API key for this call only.
Returns
A Page of occurrence arrays with items, hasMore and nextCursor. Each item has eventId, uid, start, end, allDay, summary, location, status, transparency, isOrganizer, organizerEmail, recurring, myPartstat and attendeeCount.
Example
$page = $client->calendar->listEvents( new \DateTimeImmutable('today'), new \DateTimeImmutable('today +7 days'), timezone: 'Europe/London', limit: 50,); foreach ($page as $occurrence) { echo $occurrence['start'], ' ', $occurrence['summary'], ' ', $occurrence['myPartstat'] ?? 'not invited', PHP_EOL;} if ($page->hasMore) { echo 'More from cursor ', $page->nextCursor, PHP_EOL;}Notes
The list holds your own events: the ones you made and the ones an address of yours organises or attends. For the workspace owner and their keys, an address counts as theirs unless it was given to a teammate, and
includeTeam: trueadds the rest of the workspace, apart from events somebody marked private. A member's app and a narrowed key always get their own view.myPartstatis the response recorded for one of your own addresses, or for the addresses a narrowed key covers, and null when none of them is an attendee.A narrowed key only sees occurrences whose organiser is one of the addresses it covers or where one of them is an attendee.
Cancelled events are not filtered out. Check
statusforCANCELLED.Nothing in the window is dropped. A series repeats at most once a day, so one series gives at most one row per day of the window, and every one of them is reachable through the pages.
The cursor holds the start time and event id of the last row, so an event deleted or moved between pages never breaks the walk. A cursor this list did not hand out is a 400
invalid_cursor.
Also available in
calendar->listAllEvents
Collect every occurrence inside a time window into one array
listAllEvents( DateTimeInterface|string $from, DateTimeInterface|string $to, ?string $timezone = null, ?bool $includeTeam = null, ?string $q = null, ?int $limit = null, ?string $cursor = null, ?string $apiKey = null,): arrayWalks every page of listEvents for one window and returns all of its occurrences, sorted by start time and then by event id. It follows nextCursor until hasMore is false, sending the same from, to and timezone: with each request.
A window of up to 366 days of a busy calendar can hold thousands of occurrences, so prefer iterateEvents when you can stop early.
Parameters
fromstring|DateTimeInterfaceRequiredStart of the window.
tostring|DateTimeInterfaceRequiredEnd of the window, after
fromand at most 366 days later.timezonestringIANA zone such as
Europe/London, at most 64 characters. Defaults toUTC.includeTeambooltrueadds the events of the rest of the workspace, apart from the ones marked private. Only a key of the workspace owner sees more with it. Defaults tofalse.qstringWords to look for in the title, the place and the organiser, at most 200 characters. Only events that hold every word come back, so pass a long window to find an event by name.
limitintPage size for each request, 1 to 100. The server defaults to 25.
cursorstringStarts the walk from this cursor instead of the start of the window.
apiKeystringOverrides the client API key for every page of this walk.
Returns
A list of occurrence arrays holding every occurrence in the window, earliest first.
Example
use Nextmail\Constants\CalendarTransparencies; $occurrences = $client->calendar->listAllEvents('2026-10-01T00:00:00Z', '2026-11-01T00:00:00Z', limit: 100); foreach ($occurrences as $occurrence) { if ($occurrence['transparency'] === CalendarTransparencies::OPAQUE) { echo 'Busy ', $occurrence['start'], ' to ', $occurrence['end'], PHP_EOL; }}Notes
If any page fails the call throws and the occurrences already fetched are discarded.
Also available in
calendar->iterateEvents
Stream the occurrences inside a time window one at a time
iterateEvents( DateTimeInterface|string $from, DateTimeInterface|string $to, ?string $timezone = null, ?bool $includeTeam = null, ?string $q = null, ?int $limit = null, ?string $cursor = null, ?string $apiKey = null,): GeneratorReturns a Generator over the occurrences in one window that yields them individually, earliest first, and fetches the next page only when the current one is drained. Nothing is requested until you consume it, and breaking out of the loop stops further requests, which makes it the way to find the next free slot or the next meeting without reading the whole window.
The walk ends when hasMore is false, when a page carries no nextCursor, or when the server repeats a cursor.
Parameters
fromstring|DateTimeInterfaceRequiredStart of the window.
tostring|DateTimeInterfaceRequiredEnd of the window, after
fromand at most 366 days later.timezonestringIANA zone such as
Europe/London, at most 64 characters. Defaults toUTC.includeTeambooltrueadds the events of the rest of the workspace, apart from the ones marked private. Only a key of the workspace owner sees more with it. Defaults tofalse.qstringWords to look for in the title, the place and the organiser, at most 200 characters. Only events that hold every word come back, so pass a long window to find an event by name.
limitintPage size per request, 1 to 100. The server defaults to 25.
cursorstringStarts the walk from this cursor instead of the start of the window.
apiKeystringOverrides the client API key for every page of this walk.
Returns
A Generator that yields one occurrence array per step.
Example
$from = new \DateTimeImmutable();$to = new \DateTimeImmutable('+30 days'); foreach ($client->calendar->iterateEvents($from, $to) as $occurrence) { if ($occurrence['myPartstat'] !== null) { echo 'Next meeting: ', $occurrence['start'], ' ', $occurrence['summary'], PHP_EOL; break; }}Notes
A page request that fails throws out of the
foreachloop, after every occurrence of the pages before it has been yielded.
Also available in
calendar->getEvent
Read an event with its attendees
getEvent(string $id, ?string $apiKey = null): arrayReturns a stored event with its attendees and their responses. What the server understood from the iCalendar data is structured here: recurrence holds the RRULE text, exdates the excluded instances, organizer the organiser and alarms the reminders, each an array with minutesBefore and action. The raw iCalendar source is not included, and getEventIcs serves the event as a document.
id is the event id, the eventId on an occurrence, and not the iCalendar uid. A recurring series is one event however many occurrences it has, so start and end describe its first instance. messageId and threadId link the event to mail in the mailbox when there is any.
Attendees come back in the order they were added, each with partstat, role, rsvp, cutype and respondedAt. A narrowed key gets a 404 unless one of the addresses it covers organises the event or is on the attendee list, and a key that holds a whole domain covers every address on it.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence, such ascal_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array with id, uid, sequence, summary, description, location, url, start, end, allDay, timezone, recurrence, exdates, status, transparency, visibility, organizer, isOrganizer, source, messageId, threadId, alarms, attendees, createdAt and updatedAt.
Example
$event = $client->calendar->getEvent('cal_3f9a1c7e5b2d48a06c1e9f4b'); echo $event['summary'], ', ', $event['recurrence'] ?? 'one off', PHP_EOL; foreach ($event['attendees'] as $attendee) { echo $attendee['email'], ': ', $attendee['partstat'], PHP_EOL;}Notes
status,transparencyandvisibilitycarry iCalendar values, and default toCONFIRMED,OPAQUEandPUBLIC.An attendee's
partstatdefaults toNEEDS-ACTIONandroletoREQ-PARTICIPANTuntil a response is recorded.
Also available in
calendar->getEventIcs
Download an event as an iCalendar document
getEventIcs(string $id, ?string $apiKey = null): stringReturns the event serialised as an .ics document, as a raw string rather than parsed JSON. The server sends it as text/calendar; charset=utf-8 with a download filename built from the event's uid, and the SDK requests that type and returns the body untouched.
The document declares METHOD:PUBLISH, and the content type carries no method parameter. That is deliberate: a REQUEST document makes a calendar client offer accept and decline and reply to the organiser, and this endpoint has no authority to invite anyone. Import it to show what the event currently is, not to send an invitation.
It holds one VEVENT with the attendees and their participation status, the recurrence rule, excluded dates and alarms. Lines end in CRLF and long lines are folded. DTSTAMP is the time of the request, so two downloads of an unchanged event differ on that line.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence.apiKeystringOverrides the client's API key for this call only.
Returns
A string, the iCalendar text from BEGIN:VCALENDAR to END:VCALENDAR.
Example
$ics = $client->calendar->getEventIcs('cal_8d3f0a2b9c4e41f7a6b5c2d1'); foreach (explode("\r\n", $ics) as $line) { if (str_starts_with($line, 'SUMMARY:')) { echo substr($line, 8), PHP_EOL; }}Notes
Errors still come back as JSON and throw
ApiException, so a failure never comes back as a string.Timed events are written in the zone they were created in, as local times with a
TZIDand aVTIMEZONEthat carries the rules of that zone, and all day events asDATEvalues.A narrowed key gets a 404 on the same terms as
getEvent.
Also available in
calendar->createEvent
Put an event on the calendar
createEvent(array $body, ?string $apiKey = null): arrayCreates an event, as New event on the Calendar page of the app does. start and end take a DateTimeInterface or ISO 8601 with a zone, and the SDK sends a DateTimeInterface as a UTC instant. timezone is the IANA zone the event belongs to, which decides what an all-day event means.
With attendees, an invitation goes to each of them by email from from, which has to be an address the key may send as, so the call also needs emails:send. Send 'sendInvites' => false to keep it to your own calendar.
Parameters
summarystringRequiredThe title, 1 to 255 characters.
startstring|DateTimeInterfaceRequiredWhen it starts, a
DateTimeInterfaceor ISO 8601 with a zone. ADateTimeInterfaceis sent as an instant in UTC.endstring|DateTimeInterfaceRequiredWhen it ends, after
startand at most two years later.descriptionstringNotes about the event, up to 8,000 characters.
locationstringWhere it is: a room, an address or a link.
urlstringA link that belongs to the event.
meetingUrlstringThe link to the video call, such as a Zoom, Meet or Teams address. The invitation carries it, so guests get a Join button in their calendar too, and an empty string on a change takes it off.
allDayboolWhether it fills whole days.
startandendthen mark the days.timezonestringThe IANA zone the event belongs to,
UTCunless you say.recurrencestringAn RRULE such as
FREQ=WEEKLY;BYDAY=MOwhen it repeats.attendeesarrayUp to 200 people to invite, each an array with
emailand, if you like,nameandoptional.remindersarrayUp to five reminders, each an array with
minutesBeforeand, if you like,action(DISPLAY,EMAILorAUDIO, as inNextmail\Constants\CalendarReminderActions).transparencystringOPAQUEshows you busy andTRANSPARENTfree, as inNextmail\Constants\CalendarTransparencies.visibilitystringPUBLIC,PRIVATEorCONFIDENTIAL, as inNextmail\Constants\CalendarVisibilities.sendInvitesboolFalse keeps the change to your own calendar, and sends nothing.
fromstringThe address the invitations come from. It has to be one the key may send as.
apiKeystringOverrides the client's API key for this call only.
Returns
An array for the new event, shaped like the one calendar->getEvent returns, with its attendees and their responses.
Example
$london = new \DateTimeZone('Europe/London'); $event = $client->calendar->createEvent([ 'summary' => 'Planning', 'start' => new \DateTimeImmutable('2026-10-12 09:00', $london), 'end' => new \DateTimeImmutable('2026-10-12 09:30', $london), 'timezone' => 'Europe/London', 'attendees' => [['email' => 'ada@example.com', 'name' => 'Ada Lovelace']], 'reminders' => [['minutesBefore' => 10]], 'from' => 'team@acme.com',]); echo $event['id'], ' ', $event['start'], PHP_EOL;Notes
The SDK does not retry it, because a second call makes a second event and invites everybody again.
A key that may not send as
fromis refused with 403from_address_forbidden, and an event with attendees and nofromwith 422invalid_parameter. Invitations withoutemails:sendare a 403insufficient_scope.
Also available in
calendar->updateEvent
Change an event
updateEvent(string $id, array $patch, ?string $apiKey = null): arrayChanges an event you organise. A field you leave out keeps its value, and attendees replaces the whole list. Everyone invited gets the updated invitation by email from from, so a change to an event with attendees needs emails:send too, unless sendInvites is false.
For a repeating event, scope says which dates change, as the app asks when you edit one date: occurrence changes only the date that starts at occurrenceStart, following that date and every one after it, and series all of them. With following the later dates become a new series with its own id, which is what comes back, and the old one ends the day before.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence, such ascal_followed by 24 hex characters.summarystringThe title, 1 to 255 characters.
startstring|DateTimeInterfaceWhen it starts, a
DateTimeInterfaceor ISO 8601 with a zone. ADateTimeInterfaceis sent as an instant in UTC.endstring|DateTimeInterfaceWhen it ends, after
startand at most two years later.descriptionstringNotes about the event, up to 8,000 characters.
locationstringWhere it is: a room, an address or a link.
urlstringA link that belongs to the event.
meetingUrlstringThe link to the video call, such as a Zoom, Meet or Teams address. The invitation carries it, so guests get a Join button in their calendar too, and an empty string on a change takes it off.
allDayboolWhether it fills whole days.
startandendthen mark the days.timezonestringThe IANA zone the event belongs to,
UTCunless you say.recurrencestringAn RRULE such as
FREQ=WEEKLY;BYDAY=MOwhen it repeats.attendeesarrayUp to 200 people to invite, each an array with
emailand, if you like,nameandoptional. It replaces the whole list.remindersarrayUp to five reminders, each an array with
minutesBeforeand, if you like,action(DISPLAY,EMAILorAUDIO, as inNextmail\Constants\CalendarReminderActions).transparencystringOPAQUEshows you busy andTRANSPARENTfree, as inNextmail\Constants\CalendarTransparencies.visibilitystringPUBLIC,PRIVATEorCONFIDENTIAL, as inNextmail\Constants\CalendarVisibilities.sendInvitesboolFalse keeps the change to your own calendar, and sends nothing.
fromstringThe address the invitations come from. It has to be one the key may send as.
scopestringoccurrence,followingorseries, as inNextmail\Constants\CalendarEditScopes: which dates of a repeating event change. Left out, the change reaches the event or date the id names.occurrenceStartstring|DateTimeInterfaceThe start of the date you mean, as
calendar->listEventsgives it. Needed withoccurrenceandfollowing.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the event as it stands after the change, shaped like the one calendar->getEvent returns, with sequence one higher.
Example
$event = $client->calendar->updateEvent('cal_3f9a1c7e5b2d48a06c1e9f4b', [ 'start' => '2026-10-12T10:00:00Z', 'end' => '2026-10-12T10:30:00Z', 'from' => 'team@acme.com',]); echo $event['start'], ', sequence ', $event['sequence'], PHP_EOL;Notes
The SDK does not retry it, because a retry after a lost response sends the update to everybody again.
An event organised by somebody else is refused with 403
not_organizer: answer it withrespondToEventinstead. An event the key does not reach is a 404.
Also available in
calendar->deleteEvent
Remove an event from the calendar
deleteEvent( string $id, ?string $scope = null, DateTimeInterface|string|null $occurrenceStart = null, ?string $apiKey = null,): arrayRemoves an event for good, as Remove does in the app. Nobody else is told, so call off a meeting with others in it with cancelEvent instead. For a repeating event, scope: 'occurrence' with occurrenceStart: removes one date, and scope: 'following' that date and every one after it.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence, such ascal_followed by 24 hex characters.scopestringoccurrence,followingorseries: which dates of a repeating event go.occurrenceStartstring|DateTimeInterfaceThe start of the date you mean, as
calendar->listEventsgives it. Needed withoccurrenceandfollowing.apiKeystringOverrides the client's API key for this call only.
Returns
An array with object, id and deleted set to true.
Example
$deleted = $client->calendar->deleteEvent( 'cal_3f9a1c7e5b2d48a06c1e9f4b', scope: 'occurrence', occurrenceStart: '2026-10-19T09:00:00Z',); echo $deleted['id'], ' lost one date', PHP_EOL;Notes
An event organised by somebody else is refused with 403
not_organizer, and an event that is gone or that the key does not reach is a 404. An event you may not remove can still be taken off your own calendar withcalendar->hideEvent.
Also available in
calendar->cancelEvent
Call off a meeting
cancelEvent(string $id, ?array $body = null, ?string $apiKey = null): arrayCancels a meeting you organise, as Cancel meeting does in the app. It stays on the calendar with status CANCELLED, and everyone invited is told it is off by email from from, so a meeting with attendees also needs emails:send.
For a repeating meeting, scope occurrence with occurrenceStart calls off one date, and following that date and every one after it. Guests get the matching update.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence, such ascal_followed by 24 hex characters.fromstringThe address the cancellation comes from. It has to be one the key may send as.
scopestringoccurrence,followingorseries: which dates of a repeating meeting are called off.occurrenceStartstring|DateTimeInterfaceThe start of the date you mean, as
calendar->listEventsgives it. Needed withoccurrenceandfollowing.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the event, shaped like the one calendar->getEvent returns, with status set to CANCELLED.
Example
$event = $client->calendar->cancelEvent('cal_3f9a1c7e5b2d48a06c1e9f4b', ['from' => 'team@acme.com']); echo $event['summary'], ' is now ', $event['status'], PHP_EOL;Notes
The SDK does not retry it, because a retry sends the cancellation again.
An event organised by somebody else is refused with 403
not_organizer.
Also available in
calendar->respondToEvent
Answer an invitation
respondToEvent(string $id, array $body, ?string $apiKey = null): arrayAccepts, declines or tentatively accepts an invitation, as the buttons of an invitation do in the app. The answer goes to the organiser by email from the invited address the key may send as, or from respondingAs when the invitation went to more than one of yours, so it needs emails:send as well.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence, such ascal_followed by 24 hex characters.responsestringRequiredACCEPTED,DECLINEDorTENTATIVE, as inNextmail\Constants\CalendarResponses.respondingAsstringWhich of your invited addresses answers, when there is more than one.
proposedStartstring|DateTimeInterfaceA new start to propose with your answer, a
DateTimeInterfaceor ISO 8601 with a zone, sent together withproposedEnd. ADateTimeInterfaceis sent as an instant in UTC.proposedEndstring|DateTimeInterfaceThe end of the proposed time.
apiKeystringOverrides the client's API key for this call only.
Returns
An array for the event, shaped like the one calendar->getEvent returns, with your answer on your attendee row.
Example
use Nextmail\Constants\CalendarResponses; $event = $client->calendar->respondToEvent('cal_3f9a1c7e5b2d48a06c1e9f4b', [ 'response' => CalendarResponses::ACCEPTED,]); foreach ($event['attendees'] as $attendee) { echo $attendee['email'], ': ', $attendee['partstat'], PHP_EOL;}Notes
An event that invited none of the addresses the key may send as is refused with 403
not_invited, and a cancelled meeting with 409event_cancelled.When the organiser cannot be reached, nothing changes and the call is a 409
reply_not_sent.With
proposedStartandproposedEndthe organiser gets a counter-proposal, as Propose a new time sends from Google Calendar and Outlook, and decides whether to move the meeting.
Also available in
calendar->declineProposal
Decline a proposed time
declineProposal(string $id, array $body, ?string $apiKey = null): arrayKeeps the original time of a meeting you organise after a guest proposed another one, as Keep the original does on the event in the app. The guest is told by email from from, or from the organising address, so it needs emails:send as well. To take the proposed time instead, change the event with calendar->updateEvent.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence, such ascal_followed by 24 hex characters.attendeestringRequiredThe guest whose proposal you decline, by email address.
fromstringThe address the answer is sent from, when it is not the organising address.
apiKeystringOverrides the client's API key for this call only.
Returns
An array for the event, shaped like the one calendar->getEvent returns, with the guest's proposedStart and proposedEnd cleared.
Example
$event = $client->calendar->declineProposal('cal_3f9a1c7e5b2d48a06c1e9f4b', [ 'attendee' => 'ada@example.com',]); echo $event['summary'], ' keeps its time', PHP_EOL;Notes
A guest who has not proposed a new time is refused with 404
proposal_not_found, and an event somebody else organises with 403not_organizer.
Also available in
calendar->hideEvent
Hide an event from your calendar
hideEvent(string $id, ?string $apiKey = null): arrayTakes an event off your own calendar and leaves it for everyone else, as Hide from my calendar does in the app. Use it for an invitation that reached you through a shared address, or an event you may not remove. It hides every date of a repeating event, and stops its reminders for you. calendar->unhideEvent brings it back.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence, such ascal_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array with object, id, uid and hidden set to true.
Example
$hidden = $client->calendar->hideEvent('cal_3f9a1c7e5b2d48a06c1e9f4b'); echo $hidden['id'], $hidden['hidden'] ? ' is hidden' : ' is shown', PHP_EOL;Notes
Hiding an event that is already hidden changes nothing, so it is safe to repeat. An event the key does not reach is a 404.
It hides the event for the person the key or app acts for, and nobody else.
calendar->listEventsleaves it out from then on, andcalendar->getEventstill finds it, withhiddentrue.
Also available in
calendar->unhideEvent
Show a hidden event again
unhideEvent(string $id, ?string $apiKey = null): arrayPuts an event you hid back on your calendar, as Show on my calendar does on the invitation in the app.
Parameters
idstringRequiredEvent id, the
eventIdof an occurrence, such ascal_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array with object, id, uid and hidden set to false.
Example
$shown = $client->calendar->unhideEvent('cal_3f9a1c7e5b2d48a06c1e9f4b'); echo $shown['id'], ' is on the calendar again', PHP_EOL;Notes
An event that was not hidden stays as it was, so it is safe to repeat.
Also available in
calendar->freeBusy
Free and busy times
freeBusy( array $emails, DateTimeInterface|string $from, DateTimeInterface|string $to, ?string $timezone = null, ?int $durationMinutes = null, ?string $apiKey = null,): arrayWhen the people you name are busy, as Find a time in the event editor of the app shows it. An address of the workspace shows the busy times of the person who holds it, from their events, the invitations they have not declined, their subscribed calendars and their bookings, without any detail. Any other address comes back with known false.
With durationMinutes, suggestions lists up to five times when everyone known is free, on weekdays between 09:00 and 17:00 in timezone. from and to take a DateTimeInterface or an ISO 8601 string and may be at most 31 days apart.
Parameters
emailslist<string>RequiredThe addresses to look up, at most 20.
fromstring|DateTimeInterfaceRequiredThe start of the window.
tostring|DateTimeInterfaceRequiredThe end of the window, at most 31 days after
from.timezonestringThe IANA zone the suggested times keep to working hours in,
UTCunless you say.durationMinutesintThe length of the meeting, 5 to 480 minutes. Send it to get
suggestions.apiKeystringOverrides the client's API key for this call only.
Returns
An array with people, each with email, known and busy, its busy times as arrays with start and end, and suggestions in the same shape.
Example
$times = $client->calendar->freeBusy( emails: ['ana@acme.com', 'ben@acme.com'], from: new \DateTimeImmutable('now'), to: new \DateTimeImmutable('+7 days'), timezone: 'Europe/London', durationMinutes: 30,); foreach ($times['suggestions'] as $time) { echo 'Free: ', $time['start'], PHP_EOL;}Notes
A key or an app limited to particular addresses or domains is refused with 422
capability_unsupported, because the answer reads whole calendars.It reads the calendars as they are now and holds nothing, so a suggested time can be gone a moment later.
Also available in
calendar->listFeeds
List calendar links
listFeeds(?string $apiKey = null): arrayReturns the secret links that publish your calendar to other calendar apps, as the Share tab of the calendar settings in the app lists them. Anyone with a link can read what it shows, so treat url and webcalUrl like passwords.
Parameters
apiKeystringOverrides the client's API key for this call only.
Returns
A list of arrays, each with id, name, mode, url, webcalUrl and when calendar apps last read it.
Example
foreach ($client->calendar->listFeeds() as $feed) { echo $feed['name'], ' (', $feed['mode'], '): ', $feed['url'], PHP_EOL;}Notes
A key limited to particular addresses or domains is refused with 422
capability_unsupported, because a link covers the whole calendar.
Also available in
calendar->createFeed
Create a calendar link
createFeed(array $body, ?string $apiKey = null): arrayMakes a secret link that publishes your calendar as an iCalendar feed, for Google Calendar (From URL), Outlook (Subscribe from web) or Apple Calendar (New subscription). full shows every detail, busy only the times you are busy. The calendar app reads the link again on its own schedule, usually every few hours.
Parameters
namestringRequiredThe name calendar apps show for the calendar, up to 100 characters.
modestringRequiredfullfor every detail,busyfor busy times only, as inNextmail\Constants\CalendarFeedModes.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the link with the new url and webcalUrl.
Example
use Nextmail\Constants\CalendarFeedModes; $feed = $client->calendar->createFeed(['name' => 'Work (busy)', 'mode' => CalendarFeedModes::BUSY]); echo 'Paste into Google Calendar: ', $feed['url'], PHP_EOL;Notes
One person may keep 10 links. One more is refused with 409
calendar_feed_limit.
Also available in
calendar->resetFeed
Reset a calendar link
resetFeed(string $id, ?string $apiKey = null): arrayReplaces the secret in a calendar link, so the old address stops working everywhere it was shared. Paste the new address into the calendar apps you still want to update.
Parameters
idstringRequiredCalendar link id,
cfd_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the link with its new url and webcalUrl.
Example
$feed = $client->calendar->resetFeed('cfd_3f9a1c7e5b2d48a06c1e9f4b'); echo $feed['url'], PHP_EOL;Notes
A link that is not yours is a 404
calendar_feed_not_found.
Also available in
calendar->deleteFeed
Delete a calendar link
deleteFeed(string $id, ?string $apiKey = null): arrayTurns a calendar link off for good. Calendar apps that subscribed to it stop getting updates.
Parameters
idstringRequiredCalendar link id,
cfd_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array with object, id and deleted set to true.
Example
$deleted = $client->calendar->deleteFeed('cfd_3f9a1c7e5b2d48a06c1e9f4b'); echo $deleted['id'], PHP_EOL;Notes
A link that is not yours is a 404
calendar_feed_not_found.
Also available in
calendar->listSubscriptions
List calendar subscriptions
listSubscriptions(?string $apiKey = null): arrayReturns the other calendars you subscribe to by link, such as a Google or Outlook calendar address, a team rota or public holidays, as Other calendars in the app lists them. Their events show on your calendar, read-only.
Parameters
apiKeystringOverrides the client's API key for this call only.
Returns
A list of arrays, each with name, url, color, status, lastError and how many events it holds.
Example
foreach ($client->calendar->listSubscriptions() as $subscription) { echo $subscription['name'], ': ', $subscription['status'], ', ', $subscription['eventCount'], ' events', PHP_EOL;}Notes
statusisfailingwhile reads fail and are retried, andstoppedafter ten failures in a row until you refresh it.
Also available in
calendar->createSubscription
Subscribe to a calendar
createSubscription(array $body, ?string $apiKey = null): arrayAdds a calendar by its iCalendar link, an https, http or webcal address, such as the secret address of a Google calendar or a published Outlook calendar. It is read at once, then again about every half hour. name defaults to the name the calendar gives itself.
Parameters
urlstringRequiredThe calendar link,
https,httporwebcal.namestringThe name to show, up to 100 characters.
colorstringThe colour of its events, as in
Nextmail\Constants\CalendarColors.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the subscription with its first events read.
Example
use Nextmail\Constants\CalendarColors; $holidays = $client->calendar->createSubscription([ 'url' => 'webcal://example.com/holidays.ics', 'color' => CalendarColors::GREEN,]); echo $holidays['name'], ': ', $holidays['eventCount'], ' events', PHP_EOL;Notes
An address that does not answer with a calendar is refused with 422
calendar_subscription_unreadable, and one you already subscribe to with 409calendar_subscription_exists.One person may subscribe to 20 calendars.
Also available in
calendar->updateSubscription
Change a calendar subscription
updateSubscription(string $id, array $patch, ?string $apiKey = null): arrayRenames a subscription or gives it another colour.
Parameters
idstringRequiredSubscription id,
csb_followed by 24 hex characters.namestringThe new name, up to 100 characters.
colorstringThe new colour, as in
Nextmail\Constants\CalendarColors.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the subscription as it stands now.
Example
use Nextmail\Constants\CalendarColors; $subscription = $client->calendar->updateSubscription('csb_3f9a1c7e5b2d48a06c1e9f4b', [ 'name' => 'Team rota', 'color' => CalendarColors::PURPLE,]); echo $subscription['name'], PHP_EOL;Notes
A subscription that is not yours is a 404
calendar_subscription_not_found.
Also available in
calendar->refreshSubscription
Refresh a calendar subscription
refreshSubscription(string $id, ?string $apiKey = null): arrayReads a subscribed calendar again now instead of waiting for the next half-hourly read, and restarts one that stopped after repeated failures.
Parameters
idstringRequiredSubscription id,
csb_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the subscription after the read, with status and lastError.
Example
$subscription = $client->calendar->refreshSubscription('csb_3f9a1c7e5b2d48a06c1e9f4b'); if ($subscription['lastError'] !== null) { echo 'Could not read it: ', $subscription['lastError'], PHP_EOL;}Notes
A calendar read less than a minute ago is refused with 429
calendar_subscription_refresh_too_soon.
Also available in
- API
POST /calendar/subscriptions/{id}/refresh- TypeScript
nextmail.calendar.refreshSubscription()- Python
calendar.refresh_subscription()- Ruby
calendar.refresh_subscription- Go
Calendar.RefreshSubscription- Java
calendar().refreshSubscription- C#
Calendar.RefreshSubscriptionAsync- CLI
nextmail calendar refresh-subscription
calendar->deleteSubscription
Unsubscribe from a calendar
deleteSubscription(string $id, ?string $apiKey = null): arrayRemoves a subscription and every event it brought onto your calendar.
Parameters
idstringRequiredSubscription id,
csb_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array with object, id and deleted set to true.
Example
$deleted = $client->calendar->deleteSubscription('csb_3f9a1c7e5b2d48a06c1e9f4b'); echo $deleted['id'], PHP_EOL;Notes
A subscription that is not yours is a 404
calendar_subscription_not_found.
Also available in
calendar->importIcs
Import a calendar file
importIcs(mixed $data, ?string $filename = null, ?string $apiKey = null): arraySends an iCalendar (.ics) file as the request body and queues it. Its events become events of your own that you can edit, and nobody on them is sent anything, now or when you change them later, unless you ask for that on the change. Poll calendar->getImport until status is completed.
The file may be 10 MB and hold 25,000 events. Several calendars in one file are merged, and the report keeps their names. An event whose UID is already in the workspace is skipped and counted, never overwritten, so sending the same file twice adds nothing.
data is a string of bytes, a stream resource, an SplFileInfo or a PSR-7 stream or uploaded file, and it goes out as text/calendar whatever the file is called.
Parameters
datastring|resource|SplFileInfo|StreamInterfaceRequiredThe .ics file: a string of bytes, a stream resource, an
SplFileInfoor a PSR-7 stream or uploaded file.filenamestringThe name to show for the file in the list of imports, at most 255 characters. It is not read from the file, so left out the import has
fileNamenull.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the import with object set to calendar_import and status set to queued, shaped like the one calendar->getImport returns.
Example
use Nextmail\Constants\ItemImportStatuses; $import = $client->calendar->importIcs(new \SplFileInfo('work.ics'), filename: 'work.ics'); while (in_array($import['status'], [ItemImportStatuses::QUEUED, ItemImportStatuses::RUNNING], true)) { sleep(2); $import = $client->calendar->getImport($import['id']);} echo $import['status'], ': ', $import['counts']['imported'], ' events added, ', $import['counts']['skipped'], ' left out', PHP_EOL;Notes
A body that is not an iCalendar file is a 400
not_a_calendar_file, an empty one a 400item_import_empty, and one holding more than 25,000 events a 400too_many_events.A file over 10 MB is a 413
item_import_too_large.Text you already hold, such as what
calendar->getEventIcsreturns, goes in as it is, since a PHP string is already bytes.An upload that outlasts the client's
timeoutfails as aNetworkException, so raise it on the client for a large file on a slow connection.Not retried automatically.
Also available in
calendar->listImports
List calendar imports
listImports(?int $limit = null, ?string $cursor = null, ?string $apiKey = null): PageReturns one page of the calendar files and calendars brought in, newest first, each with what it added and what it left out. Beside the files sent with calendar->importIcs it lists the calendars that came with a mailbox import, and those carry the id of that import in parentImportId.
Paging is keyset. limit: takes 1 to 100 and defaults to 25, and nextCursor goes back as cursor: while hasMore is true. calendar->listAllImports and calendar->iterateImports do that walk for you.
Parameters
limitintImports per page, a whole number from 1 to 100. The server defaults to 25.
cursorstringThe
nextCursorfrom the previous page. Never build one yourself.apiKeystringOverrides the client's API key for this call only.
Returns
A Page of import arrays, with items, hasMore and nextCursor. Each import is shaped like the one calendar->getImport returns.
Example
$page = $client->calendar->listImports(limit: 50); foreach ($page as $import) { echo $import['fileName'] ?? 'From a mailbox import', ': ', $import['status'], ', ', $import['counts']['imported'], ' added, ', $import['counts']['skipped'], ' left out', PHP_EOL;} if ($page->hasMore) { $next = $client->calendar->listImports(limit: 50, cursor: $page->nextCursor); echo count($next), ' more', PHP_EOL;}Notes
sourceisfilefor an upload.takeout,caldavandmicrosoftcame with a mailbox import.A cursor that names no import is a 400
invalid_cursor.A GET is retried automatically on network failure and on 408, 500, 502, 503 and 504 responses, up to the client's
maxRetries, and on a 429 only when it carries aRetry-Afterof a minute or less.
Also available in
calendar->listAllImports
Collect every calendar import into one array
listAllImports(?int $limit = null, ?string $cursor = null, ?string $apiKey = null): arrayFollows nextCursor from page to page and returns every calendar import, newest first.
Everything is held in memory before the call returns. Prefer calendar->iterateImports when you can stop early. limit: sets the page size of each request, not the total.
Parameters
limitintPage size per request, from 1 to 100, defaulting to 25 on the server.
cursorstringA cursor from an earlier page to start after.
apiKeystringOverrides the client's API key for every page of this walk.
Returns
A list of import arrays holding every import across all pages.
Example
$imports = $client->calendar->listAllImports(); $added = array_sum(array_map(static fn(array $import): int => (int) $import['counts']['imported'], $imports)); echo $added, ' events came from ', count($imports), ' imports', PHP_EOL;Notes
A failure on any page throws out of the whole call, and the imports already fetched are discarded.
Also available in
calendar->iterateImports
Stream calendar imports one at a time
iterateImports(?int $limit = null, ?string $cursor = null, ?string $apiKey = null): GeneratorReturns a Generator that yields calendar imports one at a time, newest first, and requests the next page only once the current one is used up. Nothing is fetched until the loop starts, and breaking out of the foreach stops the requests.
Parameters
limitintPage size per request, from 1 to 100, defaulting to 25 on the server.
cursorstringA cursor from an earlier page to start after.
apiKeystringOverrides the client's API key for every page of this walk.
Returns
A Generator that yields one import array per step.
Example
use Nextmail\Constants\ItemImportStatuses; foreach ($client->calendar->iterateImports() as $import) { if ($import['status'] === ItemImportStatuses::RUNNING) { echo 'Still running: ', $import['id'], ' with ', $import['counts']['total'], ' events', PHP_EOL; break; }}Notes
The generator is lazy, so an abandoned loop costs only the pages you consumed.
Also available in
calendar->getImport
Get a calendar import
getImport(string $id, ?string $apiKey = null): arrayReturns one calendar import with its counts and its report: the calendars it read, how many events it left out and why, and up to 20 of the events it left out. Poll it after calendar->importIcs until status is completed or failed.
counts.imported is what was added and counts.skipped what was left out, which report.skipped breaks down by reason: uid-taken for an event that was already here, no-start for one with no start time, invalid for one that could not be read and empty for a file or calendar that held no events.
Parameters
idstringRequiredCalendar import id,
iimp_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array with object set to calendar_import, id, kind, source, status, fileName, fileBytes, parentImportId, counts, report, lastError, undoable, createdAt, startedAt, finishedAt and undoneAt. counts holds total, imported, merged, skipped and failed. report holds collections, a list of arrays with name and items, skipped, a count for each reason, and samples, a list of arrays with name and reason. status is one of Nextmail\Constants\ItemImportStatuses and each reason one of Nextmail\Constants\ItemImportSkipReasons.
Example
use Nextmail\Constants\ItemImportSkipReasons; $import = $client->calendar->getImport('iimp_3f9c2a7b1e4d8f60a5c7b92d'); echo $import['status'], ': ', $import['counts']['imported'], ' added, ', $import['report']['skipped'][ItemImportSkipReasons::UID_TAKEN] ?? 0, ' already here', PHP_EOL; foreach ($import['report']['samples'] as $sample) { echo $sample['name'], ' was left out: ', $sample['reason'], PHP_EOL;}Notes
An id that names no calendar import is a 404
item_import_not_found, thrown as aNotFoundException.A GET is retried automatically on network failure and on 408, 500, 502, 503 and 504 responses, up to the client's
maxRetries, and on a 429 only when it carries aRetry-Afterof a minute or less.
Also available in
calendar->undoImport
Remove what a calendar import added
undoImport(string $id, ?string $apiKey = null): arrayDeletes every event the import added, changed since or not, and marks the import undone. Nobody is told. Events that were skipped because they were already here are not touched.
Parameters
idstringRequiredCalendar import id,
iimp_followed by 24 hex characters.apiKeystringOverrides the client's API key for this call only.
Returns
An array for the import with status set to undone and undoneAt set.
Example
use Nextmail\Exception\ConflictException; try { $undone = $client->calendar->undoImport('iimp_3f9c2a7b1e4d8f60a5c7b92d'); echo $undone['counts']['imported'], ' events removed at ', $undone['undoneAt'], PHP_EOL;} catch (ConflictException) { echo 'That import is still running or was already removed', PHP_EOL;}Notes
An import that is still running, or was already removed, is a 409
item_import_not_undoable, thrown as aConflictException.undoableon the import says whether the call would remove anything.An id that names no calendar import is a 404
item_import_not_found.Not retried automatically.
Google Workspace