> ## 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.

# Group Webhooks

> Understanding Group-related webhook events

Group webhooks notify you about changes related to group membership and updates. These events help you track when users are added to groups and when group information changes.

## Event Types

<ResponseField name="Group/User/Created" type="event">
  Triggered when a user is added to a group
</ResponseField>

## Common Properties

All group webhook events share these common properties:

<ResponseField name="occuredAt" type="integer" required>
  Timestamp when the event occurred
</ResponseField>

<ResponseField name="type" type="string" required>
  Event type identifier
</ResponseField>

<ResponseField name="body" type="object" required>
  Event-specific payload data
</ResponseField>

## Group/User/Created Event

This event is triggered whenever a user is added to a group.

### Payload Structure

<ResponseField name="user" type="object" required>
  Details about the user being added

  <Expandable title="User object properties">
    <ResponseField name="id" type="string" required>User ID</ResponseField>
    <ResponseField name="name" type="string" required>User's full name</ResponseField>
    <ResponseField name="email" type="string" required>User's email address</ResponseField>
    <ResponseField name="language" type="string" required>User's interface language</ResponseField>
    <ResponseField name="timezone" type="string" required>User's timezone</ResponseField>
    <ResponseField name="role" type="object" required>User's role information</ResponseField>
    <ResponseField name="userAttributes" type="array">Custom user attributes</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="group" type="object" required>
  Details about the group

  <Expandable title="Group object properties">
    <ResponseField name="id" type="integer" required>Group ID</ResponseField>
    <ResponseField name="name" type="string" required>Group name</ResponseField>
    <ResponseField name="description" type="string" required>Group description</ResponseField>
    <ResponseField name="image" type="object">Group cover image details</ResponseField>
  </Expandable>
</ResponseField>

## Implementation Examples

<RequestExample>
  ```bash cURL theme={null}
  # Test receiving a Group/User/Created webhook
  curl --location 'https://your-server.com/webhook' \
  --header 'Content-Type: application/json' \
  --data '{
  "type": "Group/User/Created",
  "occuredAt": 1508225229,
  "body": {
  "user": {
  "id": "1234567890",
  "name": "John Doe",
  "email": "john@example.com",
  "language": "en",
  "timezone": "Europe/London",
  "role": {
  "alias": "learner"
  },
  "userAttributes": {
  "department": "Sales",
  "employeeId": "EMP123"
  }
  },
  "group": {
  "id": 123,
  "name": "Sales Team",
  "description": "Sales department team members"
  }
  }
  }'

  # Retrieve last group webhook event
  curl --location 'https://YOURSITE.konstant.ly/openapi/v1/webhook/group.user.created/last' \
  --header 'X-API-KEY: 1qaz2wsx3edc4rfv1qaz2wsx3edc4rfv'
  ```

  ```python Python theme={null}
  from flask import Flask, request, jsonify

  app = Flask(__name__)

  @app.route('/webhook', methods=['POST'])
  def handle_webhook():
  # Get webhook data
  event_data = request.json

  # Extract common properties
  event_type = event_data['type']
  occurred_at = event_data['occuredAt']
  payload = event_data['body']

  # Handle group webhook events
  if event_type == 'Group/User/Created':
  handle_group_user_created(payload)

  # Return success quickly
  return jsonify({'status': 'success'}), 200

  def handle_group_user_created(payload):
  user = payload['user']
  group = payload['group']

  print(f"User added to group: {user['name']} (ID: {user['id']}) -> {group['name']} (ID: {group['id']})")

  # Add your group membership handling logic here
  # For example:
  # - Sync with other systems
  # - Update internal user records
  # - Send notifications
  # - Trigger automated workflows

  if __name__ == '__main__':
  app.run(port=5000)
  ```

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

  app.use(express.json());

  app.post('/webhook', (req, res) => {
  // Get webhook data
  const { type, occuredAt, body } = req.body;

  // Handle group webhook events
  try {
  if (type === 'Group/User/Created') {
  handleGroupUserCreated(body);
  }

  // Return success quickly
  res.status(200).json({ status: 'success' });
  } catch (error) {
  console.error('Error processing webhook:', error);
  res.status(500).json({ error: 'Internal server error' });
  }
  });

  function handleGroupUserCreated(payload) {
  const { user, group } = payload;

  console.log(`User added to group: ${user.name} (ID: ${user.id}) -> ${group.name} (ID: ${group.id})`);

  // Add your group membership handling logic here
  // For example:
  // - Sync with other systems
  // - Update internal user records
  // - Send notifications
  // - Trigger automated workflows
  }

  const PORT = process.env.PORT || 5000;
  app.listen(PORT, () => {
  console.log(`Webhook server running on port ${PORT}`);
  });
  ```

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

  // Webhook handling endpoint
  function handleWebhook() {
      // Get webhook data
      $eventData = json_decode(file_get_contents('php://input'), true);

  // Extract common properties
  $eventType = $eventData['type'];
  $occurredAt = $eventData['occuredAt'];
  $payload = $eventData['body'];

  // Handle group webhook events
  try {
      if ($eventType === 'Group/User/Created') {
          handleGroupUserCreated($payload);
      }

  // Return success quickly
  http_response_code(200);
  echo json_encode(['status' => 'success']);
  } catch (Exception $e) {
  error_log("Error processing webhook: " . $e->getMessage());
  http_response_code(500);
  echo json_encode(['error' => 'Internal server error']);
  }
  }

  function handleGroupUserCreated($payload) {
      $user = $payload['user'];
      $group = $payload['group'];

      error_log("User added to group: {$user['name']} (ID: {$user['id']}) -> {$group['name']} (ID: {$group['id']})");

      // Add your group membership handling logic here
      // For example:
      // - Sync with other systems
      // - Update internal user records
      // - Send notifications
      // - Trigger automated workflows
  }

  // Handle the webhook
  handleWebhook();

  ?>
  ```
</RequestExample>

## Best Practices

1. **Event Processing**

* Process events asynchronously to ensure quick response
* Implement idempotency to handle potential duplicate events
* Store raw event data for debugging and auditing

2. **Error Handling**

* Implement proper error handling and logging
* Set up monitoring for failed webhook processing
* Handle network timeouts and retries appropriately

3. **Security**

* Validate webhook source using API keys or signatures
* Use HTTPS endpoints for receiving webhooks
* Implement rate limiting and request validation

4. **Integration Tips**

* Update related systems when group membership changes
* Maintain audit logs of group membership changes
* Consider implementing event queuing for reliable processing
