Ana içeriğe geç

Login

Kullanıcı girişi yaparak API token'ı alın.

Endpoint

POST /api/v1/auth/login

Authentication

Bu endpoint authentication gerektirmez (public).

Request

Headers

HeaderDeğerZorunlu
Content-Typeapplication/jsonEvet

Request Body

ParametreTipZorunluAçıklama
emailstringEvetKullanıcı e-posta adresi
passwordstringEvetKullanıcı şifresi
device_namestringHayırCihaz adı (varsayılan: "API Client")
remember_mebooleanHayırToken'ın süresini uzat (varsayılan: false)

Example Request

{
"email": "user@example.com",
"password": "password123",
"device_name": "My Device",
"remember_me": true
}

Response

Success Response (200 OK)

{
"token": "1|abcdef1234567890...",
"user": {
"id": 1,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"email": "user@example.com",
"name": "John Doe",
"is_active": true,
"created_at": "2025-11-20T12:00:00.000000Z",
"updated_at": "2025-11-20T12:00:00.000000Z"
}
}

Error Responses

401 Unauthorized - Geçersiz Kimlik Bilgileri

{
"message": "Invalid credentials"
}

422 Unprocessable Entity - Validasyon Hatası

{
"message": "The given data was invalid.",
"errors": {
"email": ["The email field is required."],
"password": ["The password field is required."]
}
}

403 Forbidden - Pasif Kullanıcı

{
"message": "User account is inactive"
}

Code Examples

cURL

curl -X POST https://api.example.com/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123",
"device_name": "My Device",
"remember_me": true
}'

JavaScript (Fetch)

const response = await fetch('https://api.example.com/api/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'user@example.com',
password: 'password123',
device_name: 'My Device',
remember_me: true,
}),
});

const data = await response.json();
console.log(data.token); // API token'ı

PHP (Guzzle)

use GuzzleHttp\Client;

$client = new Client();

$response = $client->post('https://api.example.com/api/v1/auth/login', [
'json' => [
'email' => 'user@example.com',
'password' => 'password123',
'device_name' => 'My Device',
'remember_me' => true,
],
]);

$data = json_decode($response->getBody(), true);
echo $data['token']; // API token'ı

Python (Requests)

import requests

response = requests.post(
'https://api.example.com/api/v1/auth/login',
json={
'email': 'user@example.com',
'password': 'password123',
'device_name': 'My Device',
'remember_me': True,
}
)

data = response.json()
print(data['token']) # API token'ı

Notes

  • Token'ı güvenli bir şekilde saklayın (localStorage, secure cookie, vb.)
  • Token'ı sonraki isteklerde Authorization: Bearer \{token\} header'ı ile gönderin
  • remember_me: true ile token süresi uzatılır
  • Pasif kullanıcılar giriş yapamaz
  • Register - Yeni kullanıcı kaydı
  • Me - Mevcut kullanıcı bilgileri
  • Logout - Çıkış yap