# Set your user name

Source: https://docs.musicnerd.net/api-reference/users/update-user-name

Set your user name

## PATCH /api/user/{id}

Full OpenAPI specification: https://docs.musicnerd.net/spec/users.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: users and profile",
    "version": "1.0.0",
    "description": "The signed-in user's own account and profile: their user name, profile photo, approved claim, contributed artists, contribution summary and the updates feed. Every route answers about the caller only; the account comes from the token, never from the request."
  },
  "servers": [
    {
      "url": "https://musicnerd-api.vercel.app",
      "description": "Production"
    },
    {
      "url": "https://musicnerd-api-staging.vercel.app",
      "description": "Staging (staging database)"
    }
  ],
  "paths": {
    "/api/user/{id}": {
      "patch": {
        "summary": "Set your user name",
        "operationId": "updateUserName",
        "security": [
          {
            "privyBearer": []
          }
        ],
        "description": "Saves a chosen user name for the caller's own account and clears the confirmation flag. Names are unique case-insensitively, so a taken name is 409, and an email or wallet address is refused.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The caller's user id (a UUID).",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "example": "6f1d2e3a-4b5c-4d6e-8f90-a1b2c3d4e5f6"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "username"
                ],
                "properties": {
                  "username": {
                    "type": "string",
                    "maxLength": 50,
                    "description": "The new user name. Trimmed; 1 to 50 characters; no control characters, `@`, or a 0x wallet address."
                  }
                }
              },
              "example": {
                "username": "Vinyl Otter"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "message"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok"
                      ]
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "status": "ok",
                  "message": "User name updated"
                }
              }
            }
          },
          "400": {
            "description": "The body isn't JSON, or the name is empty, longer than 50 characters, contains control characters, or is an email or wallet address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "empty": {
                    "summary": "Empty",
                    "value": {
                      "status": "error",
                      "error": "User name is required."
                    }
                  },
                  "tooLong": {
                    "summary": "Too long",
                    "value": {
                      "status": "error",
                      "error": "User name must be 50 characters or less."
                    }
                  },
                  "emailOrWallet": {
                    "summary": "An email or wallet address",
                    "value": {
                      "status": "error",
                      "error": "Choose a user name instead of an email or wallet address."
                    }
                  },
                  "notJson": {
                    "summary": "Not JSON",
                    "value": {
                      "status": "error",
                      "error": "Invalid request body"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/NotSignedIn"
          },
          "403": {
            "description": "`id` is not the caller's own id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Forbidden"
                }
              }
            }
          },
          "409": {
            "description": "Another account already has that name (compared trimmed and case-insensitively).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "That user name is already taken. Try another."
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "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"
            }
          }
        }
      },
      "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": {
      "privyBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Access token",
        "description": "The signed-in user's access token. Copy it at https://musicnerd.net/access after signing in. Every route here answers about that user only."
      }
    }
  }
}
```
