# Admin Operations

Enterprise Grid administration including user management, team settings, and policy enforcement.

## Capabilities

### User Management

Manage users across the Enterprise Grid organization.

```typescript { .api }
/**
 * Invite a user to the workspace
 * @param options - User invitation parameters
 * @returns Promise resolving to invitation result
 */
admin.users.invite(options: AdminUsersInviteArguments): Promise<AdminUsersInviteResponse>;

/**
 * List users in the organization
 * @param options - List parameters
 * @returns Promise resolving to users list
 */
admin.users.list(options?: AdminUsersListArguments): Promise<AdminUsersListResponse>;

/**
 * Remove a user from the workspace
 * @param options - User removal parameters
 * @returns Promise resolving to removal result
 */
admin.users.remove(options: AdminUsersRemoveArguments): Promise<AdminUsersRemoveResponse>;

interface AdminUsersInviteArguments {
  /** Email address of the user to invite */
  email: string;
  /** Team ID to invite user to */
  team_id: string;
  /** Channel IDs to add user to */
  channel_ids?: string;
  /** Set to true to force invitation even if user is already invited */
  resend?: boolean;
  /** Custom message to include in invitation */
  custom_message?: string;
  /** Set user as guest */
  is_restricted?: boolean;
  /** Set user as ultra restricted guest */
  is_ultra_restricted?: boolean;
  /** Real name of the user */
  real_name?: string;
}
```

**Usage Examples:**

```typescript
import { WebClient } from "@slack/web-api";

const web = new WebClient(token);

// Invite new user
const invitation = await web.admin.users.invite({
  email: 'newuser@company.com',
  team_id: 'T1234567890',
  channel_ids: 'C1111111111,C2222222222',
  real_name: 'John Doe',
  custom_message: 'Welcome to our Slack workspace!'
});

// List all users in organization
const users = await web.admin.users.list({
  limit: 100
});

console.log(`Organization has ${users.users.length} users`);

// Remove user from workspace
await web.admin.users.remove({
  team_id: 'T1234567890',
  user_id: 'U1234567890'
});
```

### Team Management

Create and manage teams within Enterprise Grid.

```typescript { .api }
/**
 * Create a new team
 * @param options - Team creation parameters
 * @returns Promise resolving to new team details
 */
admin.teams.create(options: AdminTeamsCreateArguments): Promise<AdminTeamsCreateResponse>;

/**
 * List teams in the organization
 * @param options - List parameters
 * @returns Promise resolving to teams list
 */
admin.teams.list(options?: AdminTeamsListArguments): Promise<AdminTeamsListResponse>;

interface AdminTeamsCreateArguments {
  /** Team domain (subdomain) */
  team_domain: string;
  /** Team name */
  team_name: string;
  /** Team description */
  team_description?: string;
  /** Whether team should be discoverable by domain */
  team_discoverability?: 'open' | 'invite_only' | 'closed';
}
```

**Usage Examples:**

```typescript
// Create new team
const newTeam = await web.admin.teams.create({
  team_domain: 'engineering-team',
  team_name: 'Engineering Team',
  team_description: 'Software engineering discussions and coordination',
  team_discoverability: 'invite_only'
});

console.log('Created team:', newTeam.team.id);

// List all teams
const teams = await web.admin.teams.list();

for (const team of teams.teams) {
  console.log(`Team: ${team.name} (${team.id})`);
}
```

### Conversation Management

Administrative control over conversations across the organization.

```typescript { .api }
/**
 * Create a conversation administratively
 * @param options - Creation parameters
 * @returns Promise resolving to conversation details
 */
admin.conversations.create(options: AdminConversationsCreateArguments): Promise<AdminConversationsCreateResponse>;

/**
 * Archive conversations administratively
 * @param options - Archive parameters
 * @returns Promise resolving to archive result
 */
admin.conversations.archive(options: AdminConversationsArchiveArguments): Promise<AdminConversationsArchiveResponse>;

/**
 * Search conversations across the organization
 * @param options - Search parameters
 * @returns Promise resolving to search results
 */
admin.conversations.search(options: AdminConversationsSearchArguments): Promise<AdminConversationsSearchResponse>;

interface AdminConversationsCreateArguments {
  /** Name of the conversation */
  name: string;
  /** Whether the conversation is private */
  is_private: boolean;
  /** Team ID where conversation should be created */
  team_id?: string;
  /** Description of the conversation */
  description?: string;
  /** Whether the conversation is org-wide */
  org_wide?: boolean;
}
```

**Usage Examples:**

```typescript
// Create admin-managed channel
const adminChannel = await web.admin.conversations.create({
  name: 'company-announcements',
  is_private: false,
  org_wide: true,
  description: 'Official company-wide announcements'
});

// Search for conversations
const searchResults = await web.admin.conversations.search({
  query: 'project-alpha',
  limit: 50
});

console.log(`Found ${searchResults.conversations.length} matching conversations`);
```

### App Management

Manage applications and their permissions across the organization.

```typescript { .api }
/**
 * Approve an app installation request
 * @param options - Approval parameters
 * @returns Promise resolving to approval result
 */
admin.apps.approve(options: AdminAppsApproveArguments): Promise<AdminAppsApproveResponse>;

/**
 * Restrict an app
 * @param options - Restriction parameters
 * @returns Promise resolving to restriction result
 */
admin.apps.restrict(options: AdminAppsRestrictArguments): Promise<AdminAppsRestrictResponse>;

/**
 * List app requests
 * @param options - List parameters
 * @returns Promise resolving to requests list
 */
admin.apps.requests.list(options?: AdminAppsRequestsListArguments): Promise<AdminAppsRequestsListResponse>;

interface AdminAppsApproveArguments {
  /** App ID to approve */
  app_id: string;
  /** Team ID where app should be approved */
  team_id?: string;
  /** Request ID to approve */
  request_id?: string;
}
```

**Usage Examples:**

```typescript
// List pending app requests
const appRequests = await web.admin.apps.requests.list({
  limit: 50
});

console.log(`${appRequests.app_requests.length} pending app requests`);

// Approve app installation
await web.admin.apps.approve({
  app_id: 'A1234567890',
  team_id: 'T1234567890'
});

// Restrict app
await web.admin.apps.restrict({
  app_id: 'A1234567890',
  team_id: 'T1234567890'
});
```

### Emoji Management

Manage custom emoji across the organization.

```typescript { .api }
/**
 * Add custom emoji
 * @param options - Emoji addition parameters
 * @returns Promise resolving to addition result
 */
admin.emoji.add(options: AdminEmojiAddArguments): Promise<AdminEmojiAddResponse>;

/**
 * List custom emoji
 * @param options - List parameters
 * @returns Promise resolving to emoji list
 */
admin.emoji.list(options?: AdminEmojiListArguments): Promise<AdminEmojiListResponse>;

/**
 * Remove custom emoji
 * @param options - Removal parameters
 * @returns Promise resolving to removal result
 */
admin.emoji.remove(options: AdminEmojiRemoveArguments): Promise<AdminEmojiRemoveResponse>;

interface AdminEmojiAddArguments {
  /** Name of the emoji */
  name: string;
  /** Image data for the emoji */
  url: string;
}
```

**Usage Examples:**

```typescript
// Add custom emoji
await web.admin.emoji.add({
  name: 'company-logo',
  url: 'https://company.com/logo.png'
});

// List all custom emoji
const emojiList = await web.admin.emoji.list();

console.log(`Organization has ${emojiList.emoji.length} custom emoji`);

// Remove emoji
await web.admin.emoji.remove({
  name: 'old-emoji'
});
```

### Workspace Settings

Manage organization-wide settings and policies.

```typescript { .api }
/**
 * Set team settings
 * @param options - Settings parameters
 * @returns Promise resolving to settings update result
 */
admin.teams.settings.setDefaultChannels(options: AdminTeamsSettingsSetDefaultChannelsArguments): Promise<AdminTeamsSettingsSetDefaultChannelsResponse>;

/**
 * Set team discoverability
 * @param options - Discoverability parameters
 * @returns Promise resolving to discoverability update result
 */
admin.teams.settings.setDiscoverability(options: AdminTeamsSettingsSetDiscoverabilityArguments): Promise<AdminTeamsSettingsSetDiscoverabilityResponse>;

interface AdminTeamsSettingsSetDefaultChannelsArguments {
  /** Team ID to set default channels for */
  team_id: string;
  /** Channel IDs to set as default */
  channel_ids: string;
}
```

**Usage Examples:**

```typescript
// Set default channels for new team members
await web.admin.teams.settings.setDefaultChannels({
  team_id: 'T1234567890',
  channel_ids: 'C1111111111,C2222222222,C3333333333'
});

// Set team discoverability
await web.admin.teams.settings.setDiscoverability({
  team_id: 'T1234567890',
  discoverability: 'invite_only'
});
```

### Analytics

Access organization analytics and usage data.

```typescript { .api }
/**
 * Get analytics file
 * @param options - Analytics parameters
 * @returns Promise resolving to analytics data file
 */
admin.analytics.getFile(options: AdminAnalyticsGetFileArguments): Promise<AdminAnalyticsGetFileResponse>;

interface AdminAnalyticsGetFileArguments {
  /** Type of analytics (e.g., 'member', 'public_channel') */
  type: string;
  /** Date for the analytics data (YYYY-MM-DD) */
  date?: string;
  /** Metadata only flag */
  metadata_only?: boolean;
}
```

**Usage Examples:**

```typescript
// Get member analytics
const memberAnalytics = await web.admin.analytics.getFile({
  type: 'member',
  date: '2024-01-15'
});

// Get channel analytics  
const channelAnalytics = await web.admin.analytics.getFile({
  type: 'public_channel',
  date: '2024-01-15'
});

console.log('Analytics file URL:', memberAnalytics.file.url);
```

## Types

```typescript { .api }
interface AdminUsersInviteResponse extends WebAPICallResult {
  user: {
    id: string;
    team_id: string;
    name: string;
    email: string;
    real_name: string;
  };
}

interface AdminTeamsCreateResponse extends WebAPICallResult {
  team: {
    id: string;
    name: string;
    domain: string;
    email_domain: string;
    icon: {
      image_default: boolean;
      image_34: string;
      image_44: string;
      image_68: string;
      image_88: string;
      image_102: string;
      image_132: string;
      image_230: string;
    };
  };
}

interface AdminConversationsCreateResponse extends WebAPICallResult {
  channel_id: string;
}

interface AdminEmojiListResponse extends WebAPICallResult {
  emoji: {
    [key: string]: string;
  };
  cache_ts: string;
  categories: Array<{
    name: string;
    display_name: string;
    emoji_names: string[];
  }>;
}
```