Skip to content

Instantly share code, notes, and snippets.

@nikola-bodrozic
Created November 12, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nikola-bodrozic/81ee7b306741e36eafff596478b5e5c3 to your computer and use it in GitHub Desktop.
Save nikola-bodrozic/81ee7b306741e36eafff596478b5e5c3 to your computer and use it in GitHub Desktop.
Lufthansa REST API
<?php
// Lufthansa REST API with OAuth
// exchange client_id and client_secret for the token
$post = [
'client_id' => 'Your client Id',
'client_secret' => 'Your client secret',
'grant_type' => 'client_credentials',
];
$ch = curl_init();
// exchange credentials for token
$url = "https://api.lufthansa.com/v1/oauth/token";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$tok = json_decode($output, true);
// place the token in HTTP header to get list of airports
$ch = curl_init();
// end-point for list of airlines
curl_setopt($ch, CURLOPT_URL,"https://api.lufthansa.com/v1/references/airlines?limit=20&offset=3");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Accept: application/json',
'Authorization: Bearer '.$tok["access_token"],
'X-Originating-Ip: '.$_SERVER['SERVER_ADDR']
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
print $server_output ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment