# Search users

Source: https://docs.musicnerd.net/api-reference/admin/search-users

Search users

## GET /api/admin/users

Full OpenAPI specification: https://docs.musicnerd.net/spec/admin.json

## Authentication

This operation requires one of the security alternatives in the specification below. Security scheme definitions are included where present in the published specification.

[Authentication guide](https://docs.musicnerd.net/authentication)

## Operation and referenced schemas

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Music Nerd API: admin",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://musicnerd-api.vercel.app",
      "description": "Production"
    },
    {
      "url": "https://musicnerd-api-staging.vercel.app",
      "description": "Staging (staging database)"
    }
  ],
  "paths": {
    "/api/admin/users": {
      "get": {
        "summary": "Search users",
        "operationId": "searchAdminUsers",
        "security": [
          {
            "adminBearer": []
          }
        ],
        "description": "Users whose wallet address or username contains `search`, case-insensitive, ordered by username then wallet. Use a result's `id` to change that user's roles.",
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "required": true,
            "description": "At least 3 characters of a wallet address or username. Trimmed.",
            "schema": {
              "type": "string",
              "minLength": 3
            },
            "example": "dutch"
          }
        ],
        "responses": {
          "200": {
            "description": "The matching users; empty when none match.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "users"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok"
                      ]
                    },
                    "users": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AdminUserMatch"
                      }
                    }
                  }
                },
                "example": {
                  "status": "ok",
                  "users": [
                    {
                      "id": "0b1e4c2a-7f3d-4a58-9c61-2d8e5f7a9b10",
                      "username": "dutchyyy",
                      "wallet": null
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`search` is missing or shorter than 3 characters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Search must be at least 3 characters"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/NotSignedIn"
          },
          "403": {
            "$ref": "#/components/responses/NotAdmin"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AdminUserMatch": {
        "type": "object",
        "required": [
          "id",
          "username",
          "wallet"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "username": {
            "type": [
              "string",
              "null"
            ]
          },
          "wallet": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "status",
          "error"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "error"
            ]
          },
          "error": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "NotSignedIn": {
        "description": "No token, an invalid or expired token, or no Music Nerd user for it.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "status": "error",
              "error": "Not signed in"
            }
          }
        }
      },
      "NotAdmin": {
        "description": "The user is not an admin.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "status": "error",
              "error": "Forbidden"
            }
          }
        }
      },
      "InternalError": {
        "description": "The database could not be read or written.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "status": "error",
              "error": "Internal server error"
            }
          }
        }
      }
    },
    "securitySchemes": {
      "adminBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Access token",
        "description": "A Music Nerd admin's access token. Copy it at https://musicnerd.net/access after signing in. A signed-in user who is not an admin gets 403."
      }
    }
  }
}
```
