# Authentication

All API requests to the WhatsApp Gateway must be authenticated using **both** Basic Auth credentials and an API key provided by Namirial support.

## How to authenticate

### Basic Auth

Include your credentials in every request using HTTP Basic Authentication:


```
Authorization: Basic <base64(username:password)>
```

### API key

Include your API key in every request using the `X-Api-Key` header:


```
X-Api-Key: <your-api-key>
```

### Example (curl)


```bash
curl -X POST "https://wa.namirialtsp.com/api/services/send" \
  -H "Authorization: Basic <base64(username:password)>" \
  -H "X-Api-Key: <your-api-key>" \
  -H "Content-Type: application/json" \
  -d '{ ... }'
```

## Troubleshooting authentication issues

| HTTP Status | Error code | Error type | Solution |
|  --- | --- | --- | --- |
| `401` | 1 | `AuthenticationFailedException` | Verify your Basic Auth credentials for the target environment |
| `401` | 9 | `MissingApiKeyException` | The `X-Api-Key` header is missing. Add it to your request |
| `401` | 9 | `InvalidApiKeyException` | The `X-Api-Key` value is not valid. Verify the key for the target environment |
| `403` | 6 | `ForbiddenException` | Your account does not have the required permissions. Contact Namirial support |


**Example — invalid credentials (code 1):**


```json
{
  "type": "AuthenticationFailedException",
  "code": 1,
  "message": "Invalid credentials"
}
```

**Example — insufficient role (code 6):**


```json
{
  "type": "ForbiddenException",
  "code": 6,
  "message": "Current role [USER], missing role [ADMIN, TEMPLATE_ADMIN]"
}
```

HTTP 403 is returned when the account is authenticated but does not have the required role.

**Example — missing API key (code 9):**


```json
{
  "type": "MissingApiKeyException",
  "code": 9,
  "message": "Missing API key"
}
```

**Example — invalid API key (code 9):**


```json
{
  "type": "InvalidApiKeyException",
  "code": 9,
  "message": "Invalid API Key"
}
```

## How to get API credentials

Submit a request through the [Namirial support portal](https://support.namirial.com).