# calendars.respondToInvitation

Accept or decline emailed invitation.

Files an emailed calendar invitation to the default calendar and submits the user's RSVP response (ACCEPT, DECLINE, TENTATIVE) to the organizer.

```ts
openemail.calendars.respondToInvitation(
  identityId: string,
  body: CalendarsRespondToInvitationBody,
  options?: CallOptions,
): ApiPromise<PimRsvpResult>
```

It calls `POST /identities/{identityId}/calendars/invitations/respond`: [Accept or decline emailed invitation](/docs/api/pim/post_PimInvitationRespond) in the API reference.

## Example

```ts
const pimRsvpResult = await openemail.calendars.respondToInvitation(identityId, { partstat: 'ACCEPTED' })
```

## Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `identityId` | `string` | Identity ULID identifier. The path's `{identityId}`. |
| `body` | [`CalendarsRespondToInvitationBody`](#calendarsrespondtoinvitationbody) | The request's body. |

## Options

It takes no options of its own. Every call also takes `signal`, `timeout`, `retry` and `headers`, which say how that one call is sent ([call options](/docs/sdks/typescript/calling-methods#call-options)).

## Answer

Awaited, it is the API's JSON, [`PimRsvpResult`](/docs/sdks/typescript/types/pim-rsvp-result). It is an [`ApiPromise`](/docs/sdks/typescript/responses): `.withResponse()` gives the same with the `Response` it came in, for its headers.

## Errors

| Status | What it means |
| --- | --- |
| `400` | invalid_invitation (the body is not a parseable VEVENT) or multiple_uids (a scheduling message carries one event; overrides share its UID) |
| `401` | unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a `WWW-Authenticate: Bearer` challenge |
| `403` | not_attendee (no address of this mailbox is on the event) or is_organizer (the event names this mailbox as ORGANIZER — on ANY routing tier, not just its literal identities — an organizer answers by editing their own copy, and filing it here would schedule invitations on their behalf) |
| `404` | Mailbox not found, it has no calendar to file into, or — on the messageId form — the message is unknown (`not_found`) or carries no scheduling part (`no_invitation`) |
| `409` | conflict — the copy changed concurrently under the reply; retry |
| `413` | messageId form: message_too_large \| invitation_too_large |
| `422` | messageId form: unparseable_message \| message_too_complex |
| `503` | temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description) |

A failed call rejects with a [`RequestError`](/docs/sdks/typescript/errors): its `status`, and its `code`, the API's `error`. Decide on the code: one status covers several.

## Types

### CalendarsRespondToInvitationBody

```ts
/** The body of `calendars.respondToInvitation`. */
type CalendarsRespondToInvitationBody = {
  /** Inline form: the raw text/calendar part from the message */
  ics?: string
  /** Reference form: a message in THIS mailbox carrying the invitation */
  messageId?: string
  /** RFC 5545 PARTSTAT to record for the caller */
  partstat: ('ACCEPTED' | 'DECLINED' | 'TENTATIVE' | 'NEEDS-ACTION')
  /** Reference form, optional: the part's section as reported by …/messages/{id}/invitation. Omitted, the server picks the message's scheduling part itself */
  section?: string
}
```

It names these types of the API, each on a page of its own: [`PimRsvpResult`](/docs/sdks/typescript/types/pim-rsvp-result).
