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

# Add Team Member

## Overview

Add a new or existing user to a tenant. If the user doesn't exist, a new account will be created automatically.

## Authorization

* User must be authenticated with a valid Bearer token
* User must have ADMIN role in the specified tenant

## Behavior

* If the email doesn't exist in the system, creates a new user account
* If the user exists, adds them to the tenant with the specified role
* Sets `is_active` to true and updates `last_active_at`
* Fires a `UserRegistered` event for webhook integrations

## Validation Rules

* `email`: Required, must be a valid email format
* `role`: Required, must be either "ADMIN" or "MEMBER"

## Example Usage

```bash theme={null}
curl -X POST \
  https://faisalshop.mvp-apps.ae/api/v2/admin/team-members/1 \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "email": "newuser@example.com",
    "role": "MEMBER"
  }'
```

```javascript theme={null}
await axios.post(
  `/api/v2/admin/team-members/${tenantId}`,
  {
    email: 'newuser@example.com',
    role: 'MEMBER'
  },
  {
    headers: { Authorization: `Bearer ${token}` }
  }
);
```

## Error Responses

### Already a Member (400)

```json theme={null}
{
  "error": "user@example.com is already a member of this Organization"
}
```

### Validation Error (422)

```json theme={null}
{
  "message": "The email field must be a valid email address.",
  "errors": {
    "email": ["The email field must be a valid email address."]
  }
}
```


## OpenAPI

````yaml POST /api/v2/admin/team-members/{tenantId}
openapi: 3.1.0
info:
  title: Urban Things API
  description: Multi-tenant e-commerce platform API
  version: 2.0.0
  contact:
    email: info@faisalkc.com
servers:
  - url: https://faisalshop.mvp-apps.ae
    description: Production server
  - url: http://localhost:3000
    description: Development server
security:
  - bearerAuth: []
paths:
  /api/v2/admin/team-members/{tenantId}:
    post:
      tags:
        - Team Members
      summary: Add team member
      parameters:
        - $ref: '#/components/parameters/TenantIdPath'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - email
                - role
              properties:
                email:
                  type: string
                  format: email
                role:
                  type: string
                  enum:
                    - ADMIN
                    - MEMBER
      responses:
        '200':
          description: Member added
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
components:
  parameters:
    TenantIdPath:
      name: tenantId
      in: path
      required: true
      schema:
        type: integer
      description: Tenant ID
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````