---
title: Get user by user name
slug: custom-main-prod/get-user-by-user-name
createdAt: 2025-06-24T07:41:50.938Z
---

{
  "id": "S4T2wKoBOCKsi5fjek9NQ",
  "type": "api-oas-v2",
  "data": {
    "method": "GET",
    "url": "//petstore.swagger.io/v2/user/{username}",
    "servers": [
      {
        "url": "//petstore.swagger.io/v2/user/{username}",
        "description": "Default server"
      },
      {
        "url": "//petstore.swagger.io/sandbox/user/{username}",
        "description": "Sandbox server"
      }
    ],
    "name": "Get user by user name",
    "description": "",
    "contentType": "application/json",
    "request": {
      "pathParameters": [
        {
          "kind": "required",
          "name": "username",
          "type": "string",
          "description": "<p>The name that needs to be fetched. <em>Use user1</em> for testing.</p>"
        }
      ],
      "headerParameters": [],
      "queryParameters": [],
      "bodyDataParameters": [],
      "formDataParameters": [],
      "oAuthParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "successful operation",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "User",
            "schema": [
              {
                "name": "id",
                "kind": "optional",
                "type": "integer",
                "readOnly": true,
                "description": "",
                "modelRef": "#/components/schemas/Id",
                "customType": "Id",
                "schema": []
              },
              {
                "name": "pet",
                "kind": "optional",
                "type": "object",
                "complexType": "oneOf",
                "complexItems": [
                  {
                    "name": "Pet",
                    "description": "",
                    "modelRef": "#/components/schemas/Pet",
                    "schema": [
                      {
                        "name": "id",
                        "kind": "optional",
                        "type": "integer",
                        "readOnly": true,
                        "description": "Pet ID",
                        "modelRef": "#/components/schemas/Id",
                        "customType": "Id",
                        "schema": []
                      },
                      {
                        "name": "category",
                        "kind": "optional",
                        "type": "object",
                        "description": "Categories this pet belongs to",
                        "modelRef": "#/components/schemas/Category",
                        "customType": "Category",
                        "schema": [
                          {
                            "name": "id",
                            "kind": "optional",
                            "type": "integer",
                            "readOnly": true,
                            "description": "Category ID",
                            "modelRef": "#/components/schemas/Id",
                            "customType": "Id",
                            "schema": []
                          },
                          {
                            "name": "name",
                            "kind": "optional",
                            "type": "string",
                            "description": "Category name",
                            "example": ""
                          },
                          {
                            "name": "sub",
                            "kind": "optional",
                            "type": "object",
                            "description": "Test Sub Category",
                            "example": "",
                            "schema": [
                              {
                                "name": "prop1",
                                "kind": "optional",
                                "type": "string",
                                "description": "Dumb Property",
                                "example": ""
                              }
                            ]
                          }
                        ]
                      },
                      {
                        "name": "name",
                        "kind": "required",
                        "type": "string",
                        "description": "The name given to a pet",
                        "example": "GuruIsExample",
                        "default": "FluffyIsDefault"
                      },
                      {
                        "name": "photoUrls",
                        "kind": "required",
                        "type": "string,integer,null",
                        "description": "The list of URL to a cute photos featuring pet",
                        "example": ""
                      },
                      {
                        "name": "friend",
                        "kind": "optional",
                        "type": "object",
                        "description": "",
                        "modelRef": "#/components/schemas/Pet",
                        "customType": "Pet",
                        "schema": [
                          {
                            "name": "",
                            "description": "",
                            "customType": "Circular-Reference"
                          }
                        ]
                      },
                      {
                        "name": "tags",
                        "kind": "optional",
                        "type": "array",
                        "description": "Tags attached to the pet",
                        "modelRef": "#/components/schemas/Tag",
                        "customType": "Tag[]",
                        "schema": [
                          {
                            "name": "id",
                            "kind": "optional",
                            "type": "integer",
                            "readOnly": true,
                            "description": "Tag ID",
                            "modelRef": "#/components/schemas/Id",
                            "customType": "Id",
                            "schema": []
                          },
                          {
                            "name": "name",
                            "kind": "optional",
                            "type": "string",
                            "description": "Tag name",
                            "example": ""
                          }
                        ]
                      },
                      {
                        "name": "status",
                        "kind": "optional",
                        "type": "string<available | pending | sold>",
                        "description": "Pet status in the store",
                        "example": "",
                        "default": "pending"
                      },
                      {
                        "name": "petType",
                        "kind": "optional",
                        "type": "string",
                        "description": "Type of a pet",
                        "example": "k9"
                      },
                      {
                        "name": "huntingSkill",
                        "kind": "optional",
                        "type": "integer",
                        "example": ""
                      }
                    ]
                  },
                  {
                    "name": "Tag",
                    "description": "",
                    "modelRef": "#/components/schemas/Tag",
                    "schema": [
                      {
                        "name": "id",
                        "kind": "optional",
                        "type": "integer",
                        "readOnly": true,
                        "description": "Tag ID",
                        "modelRef": "#/components/schemas/Id",
                        "customType": "Id",
                        "schema": []
                      },
                      {
                        "name": "name",
                        "kind": "optional",
                        "type": "string",
                        "description": "Tag name",
                        "example": ""
                      }
                    ]
                  }
                ],
                "schema": []
              },
              {
                "name": "username",
                "kind": "optional",
                "type": "string",
                "description": "User supplied username",
                "example": "John78"
              },
              {
                "name": "firstName",
                "kind": "optional",
                "type": "string",
                "description": "User first name",
                "example": "John"
              },
              {
                "name": "lastName",
                "kind": "optional",
                "type": "string",
                "description": "User last name",
                "example": "Smith"
              },
              {
                "name": "email",
                "kind": "optional",
                "type": "string<email>",
                "description": "User email address",
                "example": "john.smith@example.com"
              },
              {
                "name": "password",
                "kind": "optional",
                "type": "string<password>",
                "description": "User password, MUST contain a mix of upper and lower case letters, as well as digits",
                "example": "drowssaP123"
              },
              {
                "name": "phone",
                "kind": "optional",
                "type": "string",
                "description": "User phone number in international format",
                "example": "+1-202-555-0192"
              },
              {
                "name": "userStatus",
                "kind": "optional",
                "type": "integer<int32>",
                "description": "User status",
                "example": 0
              },
              {
                "name": "image",
                "kind": "optional",
                "type": "string",
                "description": "User image",
                "example": ""
              },
              {
                "name": "addresses",
                "kind": "optional",
                "type": "array",
                "example": "",
                "itemType": "string",
                "customType": "string[]",
                "itemExample": "",
                "itemDefault": ""
              }
            ],
            "modelRef": "#/components/schemas/User",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "400",
        "description": "Invalid username supplied",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "404",
        "description": "User not found",
        "jsonExample": "",
        "isExpanded": true
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "example-0-curl",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request GET \\\n     --url //petstore.swagger.io/v2/user/{username} \\\n     --header 'accept: application/json'"
        },
        {
          "id": "example-1-javascript",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar requestOptions = {\n   method: 'GET',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"//petstore.swagger.io/v2/user/{username}\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "example-2-ruby",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"//petstore.swagger.io/v2/user/{username}\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Get.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "example-3-python",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"//petstore.swagger.io/v2/user/{username}\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"GET\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "example-0-curl"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// successful operation\n{\n  \"id\": 0,\n  \"pet\": {},\n  \"username\": \"John78\",\n  \"firstName\": \"John\",\n  \"lastName\": \"Smith\",\n  \"email\": \"john.smith@example.com\",\n  \"password\": \"drowssaP123\",\n  \"phone\": \"+1-202-555-0192\",\n  \"userStatus\": \"\",\n  \"image\": \"\",\n  \"addresses\": [\n    \"\"\n  ]\n}"
        },
        {
          "id": "response-1-400",
          "language": "400",
          "code": "// Invalid username supplied\n"
        },
        {
          "id": "response-2-404",
          "language": "404",
          "code": "// User not found\n"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}