> ## Documentation Index
> Fetch the complete documentation index at: https://docs.konstantly.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Invitations

> Get a list of processed invitations

Retrieve a list of all email invitations that have been processed on your platform.

## Request Headers

<ParamField header="X-API-KEY" type="string" required>
  API Key. Go to your Konstantly site > Settings > API and copy the value from there.
</ParamField>

## Response

<ResponseField name="invites" type="array" required>
  List of invitation objects

  <Expandable title="Invite object properties">
    <ResponseField name="id" type="integer" required>Invitation ID</ResponseField>
    <ResponseField name="email" type="string" required>Email invitation was sent to</ResponseField>
    <ResponseField name="createdAt" type="integer" required>Timestamp when invitation was sent</ResponseField>
    <ResponseField name="inviteUrl" type="string" required>URL to signup</ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request GET \
  --url 'https://YOURSITE.konstant.ly/openapi/v1/invites' \
  --header 'X-API-KEY: 1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv'
  ```

  ```python Python theme={null}
  import requests
  from dataclasses import dataclass
  from typing import List, Optional
  from datetime import datetime

  @dataclass
  class Invite:
  id: int
  email: str
  created_at: int
  invite_url: str

  @property
  def created_date(self) -> datetime:
  return datetime.fromtimestamp(self.created_at)

  def get_invitations(api_key: str) -> List[Invite]:
  """
  Fetch all processed invitations

  Args:
  api_key: Your API key

  Returns:
  List of Invite objects

  Raises:
  requests.exceptions.RequestException: If API request fails
  """
  url = "https://YOURSITE.konstant.ly/openapi/v1/invites"
  headers = {
  "X-API-KEY": api_key
  }

  try:
  response = requests.get(url, headers=headers)
  response.raise_for_status()
  data = response.json()

  return [
  Invite(
  id=invite["id"],
  email=invite["email"],
  created_at=invite["createdAt"],
  invite_url=invite["inviteUrl"]
  )
  for invite in data["invites"]
  ]

  except requests.exceptions.RequestException as e:
  print(f"Error fetching invitations: {str(e)}")
  raise

  # Example usage
  if __name__ == "__main__":
  try:
  invites = get_invitations("1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv")

  print(f"Found {len(invites)} invitations:\n")

  for invite in invites:
  print(f"ID: {invite.id}")
  print(f"Email: {invite.email}")
  print(f"Created: {invite.created_date}")
  print(f"URL: {invite.invite_url}\n")

  except Exception as e:
  print(f"Failed to fetch invitations: {str(e)}")
  ```

  ```php PHP theme={null}
  <?php

  class InvitationsAPI {
      private $apiKey;
      private $baseUrl;

      public function __construct($apiKey) {
          $this->apiKey = $apiKey;
          $this->baseUrl = 'https://YOURSITE.konstant.ly/openapi/v1';
      }

      /**
       * Get list of processed invitations
       *
       * @return array List of invitation objects
       * @throws Exception If the API request fails
       */
      public function getInvitations(): array {
          $ch = curl_init();

          $url = "{$this->baseUrl}/invites";

          curl_setopt_array($ch, [
              CURLOPT_URL => $url,
              CURLOPT_RETURNTRANSFER => true,
              CURLOPT_HTTPHEADER => [
                  'X-API-KEY: ' . $this->apiKey
              ]
          ]);

          $response = curl_exec($ch);
          $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

          if (curl_errno($ch)) {
              throw new Exception('Error: ' . curl_error($ch));
          }

          curl_close($ch);

          if ($httpCode !== 200) {
              throw new Exception("Request failed with status: {$httpCode}");
          }

          return json_decode($response, true)['invites'];
      }
  }

  // Example usage
  try {
      $api = new InvitationsAPI('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv');
      $invites = $api->getInvitations();

      echo sprintf("Found %d invitations\n\n", count($invites));

      foreach ($invites as $invite) {
          echo "ID: {$invite['id']}\n";
          echo "Email: {$invite['email']}\n";
          echo "Created: " . date('Y-m-d H:i:s', $invite['createdAt']) . "\n";
          echo "URL: {$invite['inviteUrl']}\n\n";
      }

  } catch (Exception $e) {
      echo "Error: " . $e->getMessage() . "\n";
  }
  ?>
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios');

  class InvitationsAPI {
  constructor(apiKey) {
  this.client = axios.create({
  baseURL: 'https://YOURSITE.konstant.ly/openapi/v1',
  headers: {
  'X-API-KEY': apiKey
  }
  });
  }

  /**
   * Get list of processed invitations
   * @returns {Promise<Array>} List of invitation objects
   */
  async getInvitations() {
  try {
  const response = await this.client.get('/invites');
  return response.data.invites;
  } catch (error) {
  console.error('Failed to fetch invitations:', error);
  throw error;
  }
  }

  /**
   * Format date from timestamp
   * @param {number} timestamp Unix timestamp
   * @returns {string} Formatted date
   */
  formatDate(timestamp) {
  return new Date(timestamp * 1000).toLocaleString();
  }
  }

  // Example usage
  async function main() {
  const api = new InvitationsAPI('1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv');

  try {
  const invites = await api.getInvitations();

  console.log(`Found ${invites.length} invitations\n`);

  invites.forEach(invite => {
  console.log(`ID: ${invite.id}`);
  console.log(`Email: ${invite.email}`);
  console.log(`Created: ${api.formatDate(invite.createdAt)}`);
  console.log(`URL: ${invite.inviteUrl}\n`);
  });

  } catch (error) {
  console.error('Failed to fetch invitations:', error.message);
  }
  }

  main();
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
      "invites": [
  {
      "id": 1,
      "email": "john.doe@example.com",
      "createdAt": 1234567890,
      "inviteUrl": "http://YOURSITE.konstant.ly/signup/1qaz2wsx3edc4rfv"
  },
  {
      "id": 2,
      "email": "jane.smith@example.com",
      "createdAt": 1234567891,
      "inviteUrl": "http://YOURSITE.konstant.ly/signup/2wsx3edc4rfv5tgb"
  }
      ]
  }
  ```
</ResponseExample>
