Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabaasa/5f4f641335382164d38431050b0b9905 to your computer and use it in GitHub Desktop.
Save nabaasa/5f4f641335382164d38431050b0b9905 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 ;
@nabaasa
Copy link
Author

nabaasa commented Jul 22, 2018

Helpful. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment