I am trying to make transferwise api request to get currency rates. how this code looks in python?
curl -X GET "https://api.sandbox.transferwise.tech/v1/rates?source=EUR&target=USD" \
-H "Authorization: Bearer <your api token>"
I am trying to make transferwise api request to get currency rates. how this code looks in python?
curl -X GET "https://api.sandbox.transferwise.tech/v1/rates?source=EUR&target=USD" \
-H "Authorization: Bearer <your api token>"
Don't forget that https://api.sandbox.transferwise.tech is the Base URL Sandbox (just for tests) not the Live version, so it only works with sandbox accounts (https://sandbox.transferwise.tech/login2/). Also, you gotta create your own token API in Setting (more information here).
After you have your token API set up, you can put it into an Environment Variable (.env), for the sake of security.
To use the Live Version, instead of the Sandbox, use this Base URL: https://api.transferwise.com
app.py (without environment variables):
import requests
API_TOKEN = <your API token here>
# Using Base URL LIVE
url = "https://api.transferwise.com/v1/rates?source=EUR&target=USD"
headers = {'Authorization': f'Bearer {API_TOKEN}'}
response = requests.get(url=url, headers=headers)
print(response)
import requests
url = "https://api.sandbox.transferwise.tech/v1/rates?source=EUR&target=USD"
payload = {}
headers = {
'Authorization': 'Bearer <your api token>'
}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
Also, please don't share your API tokens here.
import requests
token = "9dcdf463-be7f-41e4-bcc1-1393e71ea10e"
headers = {"Authorization": f"Bearer {token}"}
url = "https://api.sandbox.transferwise.tech/v1/rates?source=EUR&target=USD"
response = requests.get(url=url, headers=headers)
print(response.json())
{'error': 'invalid_token', 'error_description': '9dcdf463-be7f-41e4-bcc1-1393e71ea10e'}