How to Use API Key Authentication
How to use API keys in the API Portal to authorize and test APIs.
Key Authorization
- Choose the API you want to use, this example uses the Ticket API.
- Second, select the endpoint you want to use.
- Third, choose the authorization type for the API and add your API key. Bearer token: The API key is included in the request header. API key: You send the key-value pair to the API as query parameter.
- Paste your API Key.
- Set the limit.
- Select Send API Request.
- View the output.
https://dev.example.com/apis/customer-api@traefik-airlines#/
CLI
The following examples show how to use curl and HTTPIe to send API requests using an API key for authentication.
Field | Description |
---|---|
$PORTAL-URL | The base URL of your Portal, for example api.example.com . |
$API-KEY | The API key of the consumer |
Examples
API Key In Header
- Curl Command
- Output
CLI
curl -X 'GET' \
'https://$PORTAL-URL/tickets/tickets' \
-H 'accept: application/json' \
-H 'Authorization: Bearer $API-KEY'
CLI
curl -X 'GET' \
'https://$PORTAL-URL/tickets/tickets' \
-H 'accept: application/json' \
-H 'Authorization: Bearer $API-KEY'
[
{
"id": 1,
"flightCode": "TL123",
"fare": 500,
"class": "first",
"available": 5,
"total": 20
},
{
"id": 2,
"flightCode": "TL234",
"fare": 200,
"class": "economy",
"available": 2,
"total": 5
},
{
"id": 3,
"flightCode": "TL345",
"fare": 300,
"class": "business",
"available": 3,
"total": 10
}
]
API Key In Query Param
- Curl Command
- Output
CLI
curl -X 'GET' \
'https://$PORTAL_URL/tickets/tickets?limit=1&api_key=$API-KEY' \
-H 'accept: application/json'
CLI
curl -X 'GET' \
'https://$PORTAL_URL/tickets/tickets?limit=1&api_key=$API-KEY' \
-H 'accept: application/json'
[
{
"id": 1,
"flightCode": "TL123",
"fare": 500,
"class": "first",
"available": 5,
"total": 20
},
{
"id": 2,
"flightCode": "TL234",
"fare": 200,
"class": "economy",
"available": 2,
"total": 5
},
{
"id": 3,
"flightCode": "TL345",
"fare": 300,
"class": "business",
"available": 3,
"total": 10
}
]