# Postman Collection Setup Guide

## Quick Start

### 1. Import the Collection

1. Open Postman
2. Click **Import** button (top left)
3. Select the file: `Hafeez_Center_Inventory_API.postman_collection.json`
4. Click **Import**

### 2. Configure Environment Variables

The collection uses the following variables:

- `base_url`: API base URL (default: `http://127.0.0.1:8000/api/v1`)
- `access_token`: Automatically set after login

#### To Update Base URL:

1. Click on the collection name: **Hafeez Center Inventory API**
2. Go to the **Variables** tab
3. Update the `base_url` value if needed:
   - Local: `http://127.0.0.1:8000/api/v1`
   - Production: `https://api.hafeezcenter.com/api/v1`

### 3. Using the Collection

#### Step 1: Login

1. Navigate to **Authentication > Login**
2. Update the request body with your credentials:
   ```json
   {
       "email": "your@email.com",
       "password": "yourpassword"
   }
   ```
3. Click **Send**
4. The access token will be **automatically saved** to the collection variable

#### Step 2: Use Protected Endpoints

All protected endpoints (Shops) will automatically use the saved token. You don't need to manually add the Authorization header.

### 4. Testing the API

#### Authentication Flow:
1. **Login** → Get access token (automatically saved)
2. **Get Authenticated User** → Verify token works
3. **Logout** → Revoke token when done

#### Shop Operations:
1. **List Shops** → Get all shops
2. **Create Shop** → Add a new shop
3. **Get Shop** → Retrieve a specific shop (update `:id` variable)
4. **Update Shop** → Modify shop details
5. **Delete Shop** → Remove a shop

## Collection Structure

```
Hafeez Center Inventory API
├── Authentication
│   ├── Login (auto-saves token)
│   ├── Get Authenticated User
│   ├── Logout (Current Device)
│   └── Logout All Devices
└── Shops
    ├── List Shops
    ├── Get Shop
    ├── Create Shop
    ├── Update Shop
    ├── Update Shop (Partial)
    └── Delete Shop
```

## Features

### Automatic Token Management
- The **Login** request automatically saves the access token
- All protected endpoints use the saved token via Bearer authentication
- No manual token copying needed!

### Pre-configured Requests
- All requests are pre-configured with proper headers
- Example request bodies included
- Query parameters documented

### Error Handling
- Standardized error responses
- Clear error messages
- Proper HTTP status codes

## Troubleshooting

### Token Not Working?
1. Make sure you've run the **Login** request first
2. Check that the token was saved (View collection variables)
3. Verify the token hasn't expired (24 hours default)
4. Try logging in again

### 401 Unauthorized?
- Token might be expired → Login again
- Token might be invalid → Login again
- Missing Authorization header → Should be automatic, check collection settings

### 403 Forbidden?
- You're trying to access a shop that doesn't belong to you
- Only shops created by the authenticated user are accessible

### 422 Validation Error?
- Check the error response for specific field errors
- Ensure all required fields are provided
- Verify field formats (email, string lengths, etc.)

## Tips

1. **Use Collection Variables**: The `base_url` can be changed for different environments
2. **Save Responses**: Use Postman's "Save Response" feature to keep examples
3. **Create Environments**: Set up different environments (Local, Staging, Production)
4. **Use Tests**: Add automated tests to verify responses
5. **Documentation**: Each request includes detailed descriptions

## Environment Setup (Optional)

You can create Postman Environments for different servers:

### Local Environment
```
base_url: http://127.0.0.1:8000/api/v1
```

### Staging Environment
```
base_url: https://staging-api.hafeezcenter.com/api/v1
```

### Production Environment
```
base_url: https://api.hafeezcenter.com/api/v1
```

## Next Steps

1. Import the collection
2. Update credentials in the Login request
3. Run Login to get your token
4. Start testing the API!

For complete API documentation, see `API_DOCUMENTATION.md` or `openapi.yaml`.

