View Full Version : Need help with X-TBA-App-Id Header for TBA API
dirtbikerxz
28-05-2016, 12:33
What exactly am I supposed to put in the header when requesting?
For the FRC Events API V2.0 the header I use is
"Authentication: Basic *my auth key*"
What do I use for the TBA API Header? I have tried
"frc3991:scouting-system:v01"
and
"X-TBA-App-Id: frc3991:scouting-system:v01"
Neither have worked, I'm prob just missing something simple :P. Thanks for the help.
What you have should work just fine. Are you sure you're making the request with that header? If you're using a Web request function in a programming language, usually you have to set headers by name (something.setHeader("X-TBA-App-Id", "my:app:id") )
dirtbikerxz
28-05-2016, 13:09
this is probably very inneficient but for the FRC API i used a php method I found online
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: Basic *My Auth Key*"
)
);
$context = stream_context_create($opts);
$apiurl = "https://frc-api.firstinspires.org/v2.0/2016/matches/TXHO?tournamentLevel=qual&matchNumber=*";
$file = file_get_contents($apiurl, false, $context);
echo $file;
?>
That works so I tried to do the same thing with the TBA Api
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"X-TBA-App-Id: frc3991:scouting-system:v01"
)
);
$context = stream_context_create($opts);
$apiurl = "www.thebluealliance.com/api/v2/team/frc3991/2016/events";
$file = file_get_contents($apiurl, false, $context);
echo $file;
?>
but I get nothing back... (also tried only frc3991:scouting-system:v01 without the X-TBA-App-Id: portion in the header, didn't work)
this is probably very inneficient but for the FRC API i used a php method I found online
but I get nothing back... (also tried only frc3991:scouting-system:v01 without the X-TBA-App-Id: portion in the header, didn't work)
Do you get nothing back, or a JSON-ified error message?
Michael Hill
28-05-2016, 13:20
Something changed recently (not sure what), but sometimes you may have to send a User-Agent header string as well.
dirtbikerxz
28-05-2016, 13:52
Oh hell, i forgot to http:// in fornt of the url, the code was searching for the site locally without it, thanks for the help guys
Code that works if anyone cares:
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"X-TBA-App-Id: frc3991:scouting-system:v01"
)
);
$context = stream_context_create($opts);
$apiurl = "http://www.thebluealliance.com/api/v2/team/frc3991/2016/events";
$file = file_get_contents($apiurl, false, $context);
echo $file;
?>
synth3tk
28-05-2016, 14:00
That's a very... "PHP" way of handling a lack of protocol, lol! Glad you got it all figured out.
plnyyanks
28-05-2016, 14:12
Something changed recently (not sure what), but sometimes you may have to send a User-Agent header string as well.
I'm pretty sure this is caused by CloudFlare somehow (it's DDON protection might automatically stop requests that come from scripts). It's difficult to trace because it only seems to happen sometimes.
Hi, I had this same problem a while ago, where it would give me error 403, forbidden.
I found that I had to add a header called 'User-Agent' with "Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11)Gecko/20071127 Firefox/2.0.0.11" to make it think it was a web browser and wouldn't get blocked.
My code for my (python) thingy is https://github.com/Cabey4/4613-Auto-Scout
but it looks like you've already sorted it. But if anyone else gets a 403 forbidden error with the TBA/The Blue Alliance api that's probably why.
Hi, I had this same problem a while ago, where it would give me error 403, forbidden.
I found that I had to add a header called 'User-Agent' with "Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11)Gecko/20071127 Firefox/2.0.0.11" to make it think it was a web browser and wouldn't get blocked.
My code for my (python) thingy is https://github.com/Cabey4/4613-Auto-Scout
but it looks like you've already sorted it. But if anyone else gets a 403 forbidden error with the TBA/The Blue Alliance api that's probably why.
You can make things a hell of a lot simpler with the requests library. Just make sure you do pip install requests to install it and suddenly you've made everything loads easier (example (https://gist.github.com/jhtervay/f0134bdf4201cbd248da8c9b4501ef1e)).
maths222
29-05-2016, 11:53
That's a very... "PHP" way of handling a lack of protocol, lol! Glad you got it all figured out.
Really, it is the fact that PHP even lets you use "file_get_contents()" to make HTTP requests. "file_get_contents()" is better suited for local files, and CURL or something more elegant that probably wraps CURL for remote HTTP requests.
synth3tk
29-05-2016, 14:12
Really, it is the fact that PHP even lets you use "file_get_contents()" to make HTTP requests. "file_get_contents()" is better suited for local files, and CURL or something more elegant that probably wraps CURL for remote HTTP requests.
I didn't even catch that, thanks. I'm assuming that they have some reason for using file_get_contents. If not, OP, you should look into CURL (https://secure.php.net/manual/en/book.curl.php).
dirtbikerxz
29-05-2016, 14:16
I didn't even catch that, thanks. I'm assuming that they have some reason for using file_get_contents. If not, OP, you should look into CURL (https://secure.php.net/manual/en/book.curl.php).
Ya, I was only using file_get_contents because I already knew how, but I will look into CURL thanks!
Oscar Lewis
29-05-2016, 14:52
I am also currently using file_get_contents() mostly because I am only ever fetching a JSON array once (and it's only needed to set up a MySQL database once per event for scouting) but how I am forming it is
$jsonurl = "http://www.thebluealliance.com/api/v2/event/$eventcode/teams?X-TBA-App-Id=frc2557:pnwscout:v01"
or in your case
$jsonurl = "http://www.thebluealliance.com/api/v2/team/frc3991/2016/events?X-TBA-App-Id=frc3991:scouting-system:v01
Glad you got it all sorted out!
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.