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

# Networks

> Understanding Networks in the Mighty Networks API

## What is a Network?

A **Network** is the top-level organizational unit in Mighty Networks. It represents your entire community platform and contains all other resources like members, spaces, posts, and events.

Every API operation is scoped to a specific network, identified by the `network_id` parameter in your API requests.

## Network Properties

Each network includes:

* **Network ID** - Unique identifier used in all API calls
* **Name** - The display name of your network
* **Domain** - Custom domain or subdomain (e.g., `yournetwork.mn.co`)
* **Settings** - Configuration for branding, features, and permissions
* **Members** - All users who have joined your network
* **Spaces** - Organizational units within the network
* **Payment Plans** - Subscription and pricing options
* **Custom Fields** - Additional profile fields for members

## Getting Network Information

Retrieve details about your network:

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.mn.co/admin/v1/networks/{network_id}/ \
    -H "Authorization: Bearer YOUR_API_TOKEN"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch(
    `https://api.mn.co/admin/v1/networks/${NETWORK_ID}/`,
    {
      headers: {
        'Authorization': `Bearer ${API_TOKEN}`
      }
    }
  );

  const network = await response.json();
  console.log(network);
  ```

  ```python Python theme={null}
  response = requests.get(
      f"https://api.mn.co/admin/v1/networks/{NETWORK_ID}/",
      headers={"Authorization": f"Bearer {API_TOKEN}"}
  )

  network = response.json()
  print(network)
  ```
</CodeGroup>

## Network Scope

All API tokens and operations are scoped to a single network:

* API tokens can only access the network they were created for
* You cannot use one network's token to access another network
* Each network requires its own API token for authentication

<Warning>
  If you manage multiple networks, you'll need separate API tokens for each one.
</Warning>

## Network-Level Operations

The following operations are performed at the network level:

### Members Management

* List all members across the network
* Search for specific members
* Update member roles and permissions
* View network-wide member activity

### Content Management

* List all posts across all spaces
* Create posts in specific spaces
* Moderate content network-wide
* Track engagement metrics

### Administrative Tasks

* Manage network settings
* Configure custom fields
* Set up payment plans
* Manage invitations

## Common Use Cases

### Multi-Network Management

If you're managing multiple Mighty Networks:

```javascript theme={null}
const networks = [
  { id: 'network1', token: 'token1' },
  { id: 'network2', token: 'token2' }
];

for (const network of networks) {
  const response = await fetch(
    `https://api.mn.co/admin/v1/networks/${network.id}/members`,
    {
      headers: { 'Authorization': `Bearer ${network.token}` }
    }
  );

  const members = await response.json();
  console.log(`${network.id} has ${members.items.length} members`);
}
```

### Network Analytics

Pull network-wide statistics:

```javascript theme={null}
async function getNetworkStats(networkId, apiToken) {
  // Get total members
  const membersResponse = await fetch(
    `https://api.mn.co/admin/v1/networks/${networkId}/members`,
    { headers: { 'Authorization': `Bearer ${apiToken}` } }
  );

  // Get total spaces
  const spacesResponse = await fetch(
    `https://api.mn.co/admin/v1/networks/${networkId}/spaces`,
    { headers: { 'Authorization': `Bearer ${apiToken}` } }
  );

  return {
    totalMembers: membersResponse.meta?.total_count,
    totalSpaces: spacesResponse.meta?.total_count
  };
}
```

## Best Practices

1. **Store Network IDs Securely** - Keep network IDs and tokens in environment variables
2. **Use Consistent Naming** - Use clear variable names when working with multiple networks
3. **Validate Network Access** - Always verify tokens have access to the intended network
4. **Handle Errors** - Check for 401/403 errors indicating incorrect network/token pairing

## Next Steps

<CardGroup cols={2}>
  <Card title="Spaces" icon="object-group" href="/spaces">
    Learn about organizing content with Spaces.
  </Card>

  <Card title="Members" icon="users" href="/members">
    Understand member management and roles.
  </Card>

  <Card title="Authentication" icon="key" href="/authentication">
    Set up API tokens for your network.
  </Card>

  <Card title="Admin API" icon="code" href="/admin-api">
    Explore all available endpoints.
  </Card>
</CardGroup>
