Login
curl --request POST \
--url https://api.example.com/api/auth/login \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'import requests
url = "https://api.example.com/api/auth/login"
payload = {
"email": "<string>",
"password": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({email: '<string>', password: '<string>'})
};
fetch('https://api.example.com/api/auth/login', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/auth/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'email' => '<string>',
'password' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/auth/login"
payload := strings.NewReader("{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/auth/login")
.header("Content-Type", "application/json")
.body("{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/auth/login")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"200": {},
"400": {},
"401": {},
"success": true,
"data": {
"user": {
"id": 123,
"email": "<string>",
"nombre": "<string>",
"apellido": "<string>",
"telefono": "<string>",
"role": "<string>"
},
"token": "<string>"
}
}Authentication
Login
Authenticate a user with email and password
POST
/
api
/
auth
/
login
Login
curl --request POST \
--url https://api.example.com/api/auth/login \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'import requests
url = "https://api.example.com/api/auth/login"
payload = {
"email": "<string>",
"password": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({email: '<string>', password: '<string>'})
};
fetch('https://api.example.com/api/auth/login', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/auth/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'email' => '<string>',
'password' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/auth/login"
payload := strings.NewReader("{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/auth/login")
.header("Content-Type", "application/json")
.body("{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/auth/login")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"email\": \"<string>\",\n \"password\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"200": {},
"400": {},
"401": {},
"success": true,
"data": {
"user": {
"id": 123,
"email": "<string>",
"nombre": "<string>",
"apellido": "<string>",
"telefono": "<string>",
"role": "<string>"
},
"token": "<string>"
}
}Endpoint
POST /api/auth/login
Request Body
string
required
User’s email address. Must be a valid email format.
string
required
User’s password. Must be at least 1 character long.
Response
boolean
Indicates whether the request was successful.
object
Contains the authenticated user data and JWT token.
Show data properties
Show data properties
object
string
JWT authentication token valid for 7 days.
Status Codes
Success
Login successful. Returns user data and JWT token.
Bad Request
Invalid request body or validation error.
Unauthorized
Invalid credentials (incorrect email or password).
Error Response
{
"success": false,
"error": "Credenciales inválidas"
}
Example Request
cURL
curl -X POST https://api.pcfix.com/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "usuario@ejemplo.com",
"password": "miPassword123"
}'
JavaScript
const response = await fetch('https://api.pcfix.com/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'usuario@ejemplo.com',
password: 'miPassword123'
})
});
const data = await response.json();
console.log(data);
Python
import requests
response = requests.post(
'https://api.pcfix.com/api/auth/login',
json={
'email': 'usuario@ejemplo.com',
'password': 'miPassword123'
}
)
data = response.json()
print(data)
Example Response
{
"success": true,
"data": {
"user": {
"id": 123,
"email": "usuario@ejemplo.com",
"nombre": "Juan",
"apellido": "Pérez",
"telefono": "+1234567890",
"role": "USER"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
Notes
- The JWT token is valid for 7 days from the time of issuance
- Store the token securely and include it in the
Authorizationheader for authenticated requests - Password validation requires at least 1 character, but the registration endpoint enforces a minimum of 6 characters
⌘I