Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to perform GET API Call with API key in header?

I've never really attempted to try and write my own code that calls an API. I have some Python code that I created after discovering Python Requests library.

However, I can't get past this "authentication failed" error message.

The API key I have acquired is from https://fortnitetracker.com/site-api

The code I am using is as follows:

import requests
url = 'https://api.fortnitetracker.com/v1/profile/pc/ninja'
headers = {"TRN-Api-Key": "MY_KEY"}
r = requests.get(url, headers=headers)

After asking for the r.status_code I get a 403 Forbidden. When I ask for r.text I get

u'{"message":"Invalid authentication credentials"}\n'

On the API page,all they say is to pass the API key in the request headers using a GET method.

I even tried passing my credentials I used to register on the site using

r = requests.get(url, headers=headers,auth=('User', 'Pass'))

Still got the same invalid authentcation credentials error.

Is what I am doing correct? What am I missing?

Thanks for your help in advance.

like image 802
falconspy Avatar asked Oct 15 '25 13:10

falconspy


1 Answers

If you are calling an API you need to send post :

r = requests.post(url, headers=headers)

like image 198
Boris Janjetovic Avatar answered Oct 19 '25 08:10

Boris Janjetovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!