Create User
The Create User endpoint is used to create a new user account in the Petstore system.
This operation allows applications to register users by submitting account-related details such as username, email address, password, phone number, and user status.
Endpoint
Base URL
https://petstore.swagger.io/v2/user
Header
Required
Description
Content-Type
Yes
Specifies the request payload format
api_key
No
API key used for authorized requests
Supported Content Types
The endpoint supports the following content types:
Content Type
Usage
application/json
JSON request payload
application/xml
XML request payload
Request Body Parameters
Parameter
Type
Required
Description
id
integer
No
Unique identifier for the user
username
string
Yes
Username used for login
firstName
string
No
User's first name
lastName
string
No
User's last name
email
string
Yes
User email address
password
string
Yes
Account password
phone
string
No
User contact number
userStatus
integer
No
User status identifier
Sample Request
cURL Python JavaScript
curl -X POST "https://petstore.swagger.io/v2/user" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{
"id": 1001,
"username": "samdev",
"firstName": "Sam",
"lastName": "David",
"email": "sam@example.com",
"password": "Password@123",
"phone": "+91-9876543210",
"userStatus": 1
}'
import requests
url = "https://petstore.swagger.io/v2/user"
payload = {
"id" : 1001 ,
"username" : "samdev" ,
"firstName" : "Sam" ,
"lastName" : "David" ,
"email" : "sam@example.com" ,
"password" : "Password@123" ,
"phone" : "+91-9876543210" ,
"userStatus" : 1
}
response = requests . post ( url , json = payload )
print ( response . json ())
fetch ( "https://petstore.swagger.io/v2/user" , {
method : "POST" ,
headers : {
"Content-Type" : "application/json"
},
body : JSON . stringify ({
id : 1001 ,
username : "samdev" ,
firstName : "Sam" ,
lastName : "David" ,
email : "sam@example.com" ,
password : "Password@123" ,
phone : "+91-9876543210" ,
userStatus : 1
})
})
. then ( response => response . json ())
. then ( data => console . log ( data ));
Request Body Examples
Successful Response
Response Codes
Status Code
Description
200
User created successfully
400
Invalid request payload
409
Username already exists
Error Response Example
{
"code" : 400 ,
"type" : "error" ,
"message" : "Invalid user data"
}
Notes
The username, email, and password fields are recommended while creating user accounts.
Passwords should be securely managed and not exposed in client-side logs or public repositories.
Request payloads must match the selected content type.
Duplicate usernames may result in validation or conflict errors depending on the implementation.