Skip to content

Instantly share code, notes, and snippets.

@siddydutta
Created February 15, 2022 02:23
Show Gist options
  • Save siddydutta/7f06b3ba2d13d48f30f5fe4709e7372c to your computer and use it in GitHub Desktop.
Save siddydutta/7f06b3ba2d13d48f30f5fe4709e7372c to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import os
import requests
'''
Environment variables should contain the following mappings:
AMADEUS_API_KEY = YOUR_API_KEY
AMADEUS_API_SECRET = YOUR_API_SECRET
'''
AUTH_URL = "https://test.api.amadeus.com/v1/security/oauth2/token"
body = {
"grant_type": "client_credentials",
"client_id": os.getenv("AMADEUS_API_KEY"),
"client_secret": os.getenv("AMADEUS_API_SECRET"),
}
response = requests.post(AUTH_URL, data=body)
if response.status_code == 200:
access_token = response.json().get("access_token")
headers = {"Authorization": f"Bearer {access_token}"}
else:
raise Exception(response.json().get("error_description"))
@melihyildizz
Copy link

Thank you so much for this!

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