Site
Home / Forum / Developers / V2 API changes

V2 API changes


Posted: 11 Aug 2024 21:59

zag


Posts: 3,527
Joined: 2020

Version 2 of the API has been in testing for a few months now and totally free to all.

I can confirm that the free version of V2 will end this week before the big soccer leagues and NFL start. There will be a single end point and no API key in the URL any more.

The API key will be authenticated using the HTTP header variable 'X_API_KEY'. I'll post full instructions tomorrow.

Just wanted to give the heads up if anyone is already using it in production.

NOTE: There are no changes to V1 api

Posted: 11 Aug 2024 22:04

zag


Posts: 3,527
Joined: 2020

The endpoint for all Patreon supporters will be:

https://www.thesportsdb.com/api/v2/json

And use the Http header "X_API_KEY" with your API key as the text. You can test in postman or HTTPie quite easily but no longer using a web browser.



Change 'xxxxxx' to your API key.

Posted: 11 Aug 2024 22:06

zag


Posts: 3,527
Joined: 2020

There are not many changes, just a few response codes on errors. So your existing V2 code should port easily.

Example:
https://www.thesportsdb.com/api/v2/json/all/sports

Posted: 15 Aug 2024 14:44
cydalby


Posts: 346
Joined: 2020

Just to jump on the back of the earlier I thread I had, it seems like something is still not playing ball server side in regard to CORS.

This has been fine until the new V2 endpoints, as a browser (e.g. Chrome) will treat a request with no custom headers as a "simple request". Once headers are added, this then becomes a "complex request" and a preflight request will be made to the server to check whether its allowed to make this request.

All my requests from my webapp are getting CORS blocked after adding the header. It seems there may need to be some work on the server side to accept requests from origins other than internal.

This works fine using postman/curl etc as these don't have web security layers built in unlike browsers.

Some light reading here - https://blockedbycors.dev/posts/cors-preflight-request/

Cheers!

zag
Posted: 15 Aug 2024 21:10
Project-Kodi


Posts: 42
Joined: 2024

htaccess?
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"

i think we need to add OPTIONS server-side. i have the same problem.
=> OPTIONS

Java example:




zag
Posted: 19 Aug 2024 05:23
duongcuong435

Posts: 1
Joined: 2024

I use V2 using header(X_API_KEY) to call API but only get response from API:
Ex: https://www.thesportsdb.com/api/v2/json/schedual/next/league/4393
Response:
{
"Message": "Incorrect API key"
}
Looking forward to hearing from you soon.

Posted: 19 Aug 2024 07:49

zag


Posts: 3,527
Joined: 2020

URL API keys removed from V2 API now. You can only use the main URL with the key in the header.

Checking CORS today, but I thought it was already enabled...

Posted: 19 Aug 2024 08:12

zag


Posts: 3,527
Joined: 2020

htaccess?
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"

i think we need to add OPTIONS server-side. i have the same problem.
=> OPTIONS

Java example:




OK this has now been updated to include GET, PUT, POST, DELETE, OPTIONS

Posted: 19 Aug 2024 08:13

zag


Posts: 3,527
Joined: 2020

This works fine using postman/curl etc as these don't have web security layers built in unlike browsers.

Some light reading here - https://blockedbycors.dev/posts/cors-preflight-request/

Cheers!


Hopefully now fixed, but let me know if there is a simple test I can do or if you let me know if there are still issues.

Posted: 19 Aug 2024 08:21
Project-Kodi


Posts: 42
Joined: 2024

Working!

Here a little test and documentation: https://tsdb.club/Thread-Changes-between-API-V1-and-API-V2-migration-assistance

Posted: 19 Aug 2024 08:51

zag


Posts: 3,527
Joined: 2020

Big thanks to Project-Kodi for helping with the testing, this should now be fixed I hope.

Posted: 19 Aug 2024 11:40
cydalby


Posts: 346
Joined: 2020

Thanks guys this is all working now!

Appreciate it

Posted: 21 Aug 2024 19:33
smathers


Posts: 42
Joined: 2023

Had success at the weekend using the new v2 livescores API and my new API Key, BUT tonight I noticed that my livescores were broken again. Debug found it to be that my API-KEY had changed! Lucky again, that I don't have to make a new app release in order to fix this, and can do it via AWS, but I need to ensure that this isn't going to unexpectedly change again.

Posted: 26 Aug 2024 21:04

zag


Posts: 3,527
Joined: 2020

Had success at the weekend using the new v2 livescores API and my new API Key, BUT tonight I noticed that my livescores were broken again. Debug found it to be that my API-KEY had changed! Lucky again, that I don't have to make a new app release in order to fix this, and can do it via AWS, but I need to ensure that this isn't going to unexpectedly change again.

Yes its all complete now.

Had to make some changes to API keys for a few users, seems you were the unlucky one sorry!

A reminder that V2 is still in beta development phase. But hopefully its nailed down now.

smathers
Posted: 27 Aug 2024 12:05
webful


Posts: 1
Joined: 2023

Hi,

I'm a Patreon and I'm trying to migrate to the new X_API_KEY header but i'm getting "Incorrect API key" and my profile doesn't show my API key anymore. I've tried on Postman and within code with both GET & POST but get the same error.

Seems like my API key has been deleted?

Thanks in advance
Tom

Posted: 27 Aug 2024 23:19

zag


Posts: 3,527
Joined: 2020

Hi,

I'm a Patreon and I'm trying to migrate to the new X_API_KEY header but i'm getting "Incorrect API key" and my profile doesn't show my API key anymore. I've tried on Postman and within code with both GET & POST but get the same error.

Seems like my API key has been deleted?

Thanks in advance
Tom


Either pm me on discord or email at [email protected], should be an easy fix if you are a current patreon subscriber.

Posted: 02 Sep 2024 21:28

zag


Posts: 3,527
Joined: 2020

Just a small update to say that the /schedual endpoint has been renamed to /schedule

And the header has been renamed from 'X_API_KEY' to 'X-API-KEY'

Both should still work, but eventually the old mis-spelling 'schedual' will be removed.
X-API-KEY is now recommended, although the underscore way will also work indefinitely.

All docs and examples updated.

Thanks all again for pointing out these silly errors. V2 going from alpha to beta soon


Who is Online?

In total there are 68 users online :: 3 registered, 0 hidden and 65 guests (based on users active over the past 5 minutes) Most users ever online was 424 on Fri Nov 10, 2017 9:02 pm

About Us

Discussion forum for TheSportsDB.com site and related topics

Rules

- Be Polite
- Respect other users
- Always post log files with issues
- Try to be helpful
- No Piracy discussion

Showing 0 to 17 (Total: 17)