-1

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>"
1

3 Answers 3

3

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)
Sign up to request clarification or add additional context in comments.

1 Comment

This is the first place I found advice regarding sandbox vs live, and it seems to be the solution to OP's problem as well... This should be the accepted answer.
0
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.

2 Comments

yes i know but its an error i get: b'{"error":"invalid_token","error_description":"9dcdf463-be7f-41e4-bcc1-1393e71ea10e"}' is my token invalid? can you please try and get information with my token or yours?
According to this message, yes it is an invalid token.
0
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())

4 Comments

Did it worked for you? I got: {'error': 'invalid_token', 'error_description': '9dcdf463-be7f-41e4-bcc1-1393e71ea10e'}
seems like token is invalid. you should get a new token.
I tried with second token too. Can you please do it with your token and give me screenshot of python compiler? i am interested in how it works
it also gives me the same error {'error': 'invalid_token', 'error_description': '9dcdf463-be7f-41e4-bcc1-1393e71ea10e'}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.