code: def invite_to_workspace(
      *,
      username: Optional[str] = None,
      email: Optional[str] = None,
      workspace: str,
      api_token: Optional[str] = None,
      role: Union[
          WorkspaceMemberRole, str
      ] = WorkspaceMemberRole.MEMBER,
      add_to_all_projects: bool = False,
  ) -> None:
      """Creates an invitation to a Neptune workspace.
  
      Provide either the username or email of the person to invite.
  
      Args:
          username: username of the user to invite. Note: If you provide this, leave out the email argument.
          email: email of the user to invite. Note: If you provide this, leave out the username argument.
          workspace: Name of your Neptune workspace.
          api_token: User's API token.
              If None, the value of the NEPTUNE_API_TOKEN environment variable is used.
              Note: To keep your token secure, use the NEPTUNE_API_TOKEN environment variable rather than placing your
              API token in plain text in your source code.
          role: The workspace role that is to be granted to the invited user.
              You can choose between the following values: "admin" and "member".
          add_to_all_projects: Whether to add the invited user to all projects in the workspace.
  
      Example:
          >>> from neptune import management
          >>> management.invite_to_workspace(
          ...     username="user",
          ...     workspace="ml-team",
          ...     role="admin",
          ... )
  
      Learn more in the docs:
      - https://docs.neptune.ai/api/management/#invite_to_workspace
      - https://docs.neptune.ai/management/inviting_people/
      """
      verify_type("workspace", workspace, str)
      verify_type("role", role, (WorkspaceMemberRole, str))
      verify_type("add_to_all_projects", add_to_all_projects, bool)
      verify_type("username", username, (str, type(None)))
      verify_type("email", email, (str, type(None)))
      verify_type("api_token", api_token, (str, type(None)))
  
      if username and email:
          raise ValueError(
              "Cannot specify both `username` and `email`."
          )
  
      if username:
          invitee = username
          invitation_type = "user"
      elif email:
          invitee = email
          invitation_type = "emailRecipient"
      else:
          raise ValueError(
              "Neither `username` nor `email` arguments filled. At least one needs to be passed"
          )
  
      if isinstance(role, str):
          role = WorkspaceMemberRole(role)
  
      params = {
          "newOrganizationInvitations": {
              "invitationsEntries": [
                  {
                      "invitee": invitee,
                      "invitationType": invitation_type,
                      "roleGrant": role.to_api(),
                      "addToAllProjects": add_to_all_projects,
                  }
              ],
              "organizationIdentifier": workspace,
          },
          **DEFAULT_REQUEST_KWARGS,
      }
  
      backend_client = _get_backend_client(api_token=api_token)
      try:
          backend_client.api.createOrganizationInvitations(**params)
      except HTTPNotFound:
          raise WorkspaceOrUserNotFound(
              workspace=workspace, user=invitee
          )
      except HTTPConflict:
          raise UserAlreadyInvited(user=invitee, workspace=workspace)
  
imports: import os
  from typing import Dict, Iterable, List, Optional, Union
  from bravado.exception import HTTPBadRequest, HTTPConflict, HTTPForbidden, HTTPNotFound, HTTPUnprocessableEntity
  from neptune.common.backends.utils import with_api_exceptions_handler
  from neptune.common.envs import API_TOKEN_ENV_NAME
  from neptune.internal.backends.hosted_client import DEFAULT_REQUEST_KWARGS, create_backend_client, create_http_client_with_auth, create_leaderboard_client
  from neptune.internal.backends.swagger_client_wrapper import SwaggerClientWrapper
  from neptune.internal.backends.utils import parse_validation_errors, ssl_verify
  from neptune.internal.credentials import Credentials
  from neptune.internal.id_formats import QualifiedName
  from neptune.internal.utils import verify_collection_type, verify_type
  from neptune.internal.utils.iteration import get_batches
  from neptune.internal.utils.logger import logger
  from neptune.management.exceptions import AccessRevokedOnDeletion, AccessRevokedOnMemberRemoval, AccessRevokedOnServiceAccountRemoval, BadRequestException, ProjectAlreadyExists, ProjectNotFound, ServiceAccountAlreadyHasAccess, ServiceAccountNotExistsOrWithoutAccess, ServiceAccountNotFound, UserAlreadyHasAccess, UserAlreadyInvited, UserNotExistsOrWithoutAccess, WorkspaceNotFound, WorkspaceOrUserNotFound
  from neptune.management.internal.dto import ProjectMemberRoleDTO, ProjectVisibilityDTO, ServiceAccountDTO, WorkspaceMemberRoleDTO
  from neptune.management.internal.types import ProjectVisibility
  from neptune.management.internal.utils import WorkspaceMemberRole, extract_project_and_workspace, normalize_project_name
label_desc: Use image node_id 18 for calling a global function with example usage: invite_to_workspace() without return types