Created
February 15, 2022 02:23
-
-
Save siddydutta/7f06b3ba2d13d48f30f5fe4709e7372c to your computer and use it in GitHub Desktop.
Python script for Amadeus API Authorization (https://developers.amadeus.com/self-service/apis-docs/guides/authorization-262)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for this!