Connect and Test WAP API Login
Verify WAP API authentication with cURL, Python Requests and PHP cURL examples using API headers and the expected login response.
After creating API credentials, send a request to the WAP API root. This checks which identity the request authenticated as. It does not return a token to reuse.
Request
| Property | Value |
|---|---|
| Methods | GET or POST; examples use POST. |
| Versioned URL | https://server.example.com:5555/api/v1/ |
| Default URL | https://server.example.com:5555/api/ |
| Required headers | X-API-USER, X-API-PASSWORD |
| Operation parameters | None. |
Run these examples from the trusted integration host, with a valid HTTPS certificate and network access to WAP. Keep TLS verification enabled. Do not follow a redirect to an unexpected host with credential headers.
Configure the examples
Each example is standalone. Replace server.example.com, billing_api and YOUR_API_PASSWORD directly with your server hostname and API credentials. These are illustrative placeholders, not working credentials.
cURL example
curl --silent --show-error --include \
--connect-timeout 5 --max-time 30 \
--request POST \
--header 'X-API-USER: billing_api' \
--header 'X-API-PASSWORD: YOUR_API_PASSWORD' \
'https://server.example.com:5555/api/v1/'--include displays the HTTP status and headers alongside the body. Inspect both; a completed cURL transfer alone does not mean authentication succeeded.
Python example
Use Python 3 with the requests package installed in your client environment. Save as check_wap_login.py and replace the example hostname, API username and password.
import json
import requests
base_url = "https://server.example.com:5555/api/v1/"
api_user = "billing_api"
api_password = "YOUR_API_PASSWORD"
headers = {
"X-API-USER": api_user,
"X-API-PASSWORD": api_password,
}
try:
response = requests.post(
base_url,
headers=headers,
timeout=(5, 30),
allow_redirects=False,
)
if response.status_code != 200:
raise RuntimeError(f"HTTP {response.status_code}: {response.text}")
result = response.json()
if not isinstance(result, dict):
raise RuntimeError("Expected a JSON object")
if result.get("username") != api_user:
raise RuntimeError("The response did not confirm the expected API user")
print(json.dumps(result, indent=2))
except (requests.RequestException, ValueError, RuntimeError) as error:
raise SystemExit(f"API login check failed: {error}")PHP example
Use PHP 8 or later with the cURL extension. Save as check_wap_login.php and run it from the CLI after replacing the example values.
<?php
try {
$url = 'https://server.example.com:5555/api/v1/';
$apiUser = 'billing_api';
$apiPassword = 'YOUR_API_PASSWORD';
$ch = curl_init($url);
if ($ch === false) {
throw new RuntimeException('Unable to initialize cURL');
}
try {
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => '',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_HTTPHEADER => [
'X-API-USER: ' . $apiUser,
'X-API-PASSWORD: ' . $apiPassword,
],
]);
$body = curl_exec($ch);
if ($body === false) {
throw new RuntimeException(curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
} finally {
curl_close($ch);
}
if ($httpCode !== 200) {
throw new RuntimeException('HTTP ' . $httpCode . ': ' . $body);
}
$result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
if (!is_array($result) || ($result['username'] ?? null) !== $apiUser) {
throw new RuntimeException('The response did not confirm the expected API user');
}
echo json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) . PHP_EOL;
} catch (Throwable $error) {
fwrite(STDERR, 'API login check failed: ' . $error->getMessage() . PHP_EOL);
exit(1);
}Expected response
With the example API username, HTTP 200 returns:
{
"username": "billing_api",
"auth": "None"
}The current handler stringifies an empty authentication value as "None". This is a string, not a bearer token and not JSON null. An example showing "auth": "API" does not match this handler.
If the request fails
| Result | What to check |
|---|---|
| Connection/TLS failure | Hostname, port 5555, firewall, certificate trust and hostname match. Correct the cause rather than disabling TLS verification. |
HTTP 403 with detail | Missing/incorrect API credentials or source-IP restriction. A rejected IP and a bad password can both produce Invalid API credentials. |
| Redirect or HTML | Verify the direct API URL and any intervening proxy/login page. These clients do not follow redirects. |
| Unexpected username | Check stale headers and browser-session cookies. Test with an independent client using the intended account. |
For header-only clients without session cookies, missing credentials currently produce {"detail":"Authentication credentials were not provided."}; rejected credentials produce {"detail":"Invalid API credentials"}. Authentication errors do not use the operation's data/info/status shape.
Next, call test_connection. It verifies access to an API operation and has separate demo-mode behavior.