# How to Get Valid Amadeus API Credentials

## Step-by-Step Guide

### 1. Create an Amadeus Developer Account
1. Go to [Amadeus for Developers](https://developers.amadeus.com/)
2. Click "Register" in the top right corner
3. Fill in your details and create an account
4. Verify your email address

### 2. Create a New App
1. Log in to your Amadeus developer account
2. Go to [My Self-Service Workspace](https://developers.amadeus.com/my-apps)
3. Click "Create new app"
4. Fill in the app details:
   - **App Name**: B2B Flight Ticketing Platform (or any name you prefer)
   - **Description**: Flight booking and ticketing system
   - **Callback URL**: http://localhost:8081/callback (optional for this integration)
5. Click "Create"

### 3. Get Your API Credentials
1. After creating the app, you'll see your app in the dashboard
2. Click on your app name to view details
3. You'll see two important credentials:
   - **API Key** (also called Client ID)
   - **API Secret** (also called Client Secret)
4. Copy both values

### 4. Choose Your Environment

Amadeus provides two environments:

#### Test Environment (Recommended for Development)
- **Base URL**: `https://test.api.amadeus.com`
- Uses test data and fake bookings
- Free to use
- No real money transactions
- Perfect for development and testing

#### Production Environment
- **Base URL**: `https://api.amadeus.com`
- Uses real flight data
- Real bookings with real airlines
- Requires billing setup
- Use only when ready to go live

### 5. Update Your Application

Once you have your credentials, update the `.env` file:

```bash
# Replace with your actual credentials
AMADEUS_API_KEY=your_actual_api_key_here
AMADEUS_API_SECRET=your_actual_api_secret_here

# For test environment (recommended)
AMADEUS_API_BASE_URL=https://test.api.amadeus.com

# For production (only when ready)
# AMADEUS_API_BASE_URL=https://api.amadeus.com
```

### 6. Test Your Credentials

Run the test script to verify your credentials:

```bash
./test-amadeus-credentials.sh
```

You should see:
```
✅ SUCCESS! Your Amadeus credentials are valid.
```

### 7. Restart Your Application

```bash
docker-compose restart app
```

### 8. Verify the Integration

Check the health endpoint:
```bash
curl http://localhost:8081/actuator/health
```

You should see `"amadeusApi":{"status":"UP"}` in the response.

## Common Issues

### Issue: "Client credentials are invalid"
**Solution**: Double-check that you copied the API Key and Secret correctly. Make sure there are no extra spaces or characters.

### Issue: "Invalid grant type"
**Solution**: Make sure you're using `grant_type=client_credentials` in the OAuth request.

### Issue: "Insufficient scope"
**Solution**: In your Amadeus app settings, make sure you have enabled the APIs you want to use:
- Flight Offers Search
- Flight Offers Price
- Flight Create Orders
- Flight Order Management

### Issue: Rate Limiting
**Solution**: The test environment has rate limits. If you hit them, wait a few minutes or upgrade to a paid plan.

## API Limits (Test Environment)

- **Requests per second**: 10
- **Requests per month**: 2,000 (free tier)
- **Data**: Test data only, not real flights

## API Limits (Production Environment)

- **Requests per second**: Depends on your plan
- **Requests per month**: Depends on your plan
- **Billing**: Pay-as-you-go or monthly subscription
- **Data**: Real flight data and bookings

## Useful Links

- [Amadeus Developer Portal](https://developers.amadeus.com/)
- [My Apps Dashboard](https://developers.amadeus.com/my-apps)
- [API Documentation](https://developers.amadeus.com/self-service)
- [Flight Offers Search API](https://developers.amadeus.com/self-service/category/flights/api-doc/flight-offers-search)
- [Flight Create Orders API](https://developers.amadeus.com/self-service/category/flights/api-doc/flight-create-orders)
- [Support](https://developers.amadeus.com/support)

## Need Help?

If you're having trouble getting credentials:
1. Check the [Amadeus Developer Forum](https://developers.amadeus.com/support)
2. Contact Amadeus support through the developer portal
3. Review the [Getting Started Guide](https://developers.amadeus.com/get-started/get-started-with-self-service-apis-335)

---

**Note**: Keep your API credentials secure! Never commit them to git or share them publicly. The `.env` file is already in `.gitignore` to prevent accidental commits.
