# Add Members to an Organization

This page shows how to use the Pollination API to add members to an organization from a list. There is an additional check not to overwite the existing member. This check is useful to ensure the existing organization owners are not being changed to members.

```python
import requests
import pathlib
import time

from typing import List


def get_current_users(api_key: str, org_name: str) -> List[str]:
    """This functions returns an empty list if the api_key doesn't belong to an organization owner."""
    url = f'https://api.pollination.solutions/orgs/{org_name}/members'
    response = requests.get(
            url=url,
            headers={'x-pollination-token': api_key}
        )
    response.raise_for_status()
    members_info = response.json()['resources']
    current_users = [
        user_info['user']['username'] for user_info in members_info
    ]
    return current_users


def add_users_to_org(
    api_key: str,
    user_handles: List[str],
    org_name: str,
    role: str = 'member',
    overwrite: bool = False
        ):

    # get current users
    current_users = get_current_users(api_key=api_key, org_name=org_name) \
        if not overwrite else []

    for handle in user_handles:
        if handle in current_users:
            print(f'{handle} is already a member of {org_name}')
            continue
        print(f'Adding {handle} to {org_name} as a {role}')
        url = f'https://api.pollination.solutions/orgs/{org_name}/members/{handle}/{role}'
        response = requests.patch(
            url=url,
            headers={'x-pollination-token': api_key}
        )
        response.raise_for_status()
        time.sleep(0.5)
        
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pollination.solutions/user-manual/developers/api/add-members.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
