Go client for the 2. Basketball Bundesliga public API.
Based on the official API documentation: https://wiki.2basketballbundesliga.de/index.php/API
go get github.com/Senseering/2bbl-go-sdkpackage main
import (
"context"
"fmt"
"log"
bbl "github.com/Senseering/2bbl-go-sdk"
)
func main() {
client := bbl.NewClient("your-api-key")
ctx := context.Background()
// Get ProA standings
standings, err := client.GetStandings(ctx, bbl.TableProA)
if err != nil {
log.Fatal(err)
}
fmt.Printf("League: %s (%s)\n", standings.Meta.League, standings.Meta.Season)
for _, row := range standings.Table {
fmt.Printf("#%d %s — %d pts (%d-%d)\n",
row.Pos.Value, row.TeamCaption, row.Points.Value,
row.Wins.Value, row.Losses.Value)
}
}// Custom HTTP client (e.g. for timeouts or middleware)
client := bbl.NewClient("your-api-key",
bbl.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}),
)
// Custom base URL (e.g. for testing)
client := bbl.NewClient("your-api-key",
bbl.WithBaseURL("http://localhost:8080"),
)Every endpoint requires a club/partner API key provided when creating the client.
// Get schedule for a competition and season
schedule, err := client.GetSchedule(ctx, bbl.CompProA, "2023-2024")
// Access matchday games
for day, games := range schedule.Matchdays {
fmt.Printf("Matchday %d: %d games\n", day, len(games))
}Competitions: CompProA, CompProAPO, CompProBNord, CompProBSued, CompProBPO, CompProBNordPD, CompProBSuedPD, CompBBLPokal
standings, err := client.GetStandings(ctx, bbl.TableProA)Competitions: TableProA, TableProBNord, TableProBSued, TableProBNordPD, TableProBSuedPD
// Returns all currently live games (always as a slice)
games, err := client.GetLiveGames(ctx)// Get scoreboard snapshot for a game
game, err := client.GetSwissTimingGame(ctx, "2003328.JSN")
// Get play-by-play actions for a quarter
actions, err := client.GetQuarterActions(ctx, "2003328Q1.JSN")
// Get raw JSON for any livedata file
raw, err := client.GetSwissTimingRaw(ctx, "2003328.JSN")// Own team roster (team API key)
roster, err := client.GetRoster(ctx)
// Specific team roster (partner API key)
roster, err := client.GetRosterByTeam(ctx, "447")stats, err := client.GetStats(ctx, bbl.PhaseRegularSeason)
// Total values
for _, p := range stats.Totals {
fmt.Printf("%s %s: %.0f pts\n", p.Firstname, p.Lastname, p.Points.Value)
}
// Per-game averages
for _, p := range stats.Averages {
fmt.Printf("%s %s: %.1f ppg\n", p.Firstname, p.Lastname, p.Points.Value)
}Phases: PhaseRegularSeason (hauptrunde), PhasePlayoffs (po), PhasePlaydowns (pd)
The 2BBL API frequently returns numeric values as strings and uses inconsistent typing. This SDK handles this transparently with custom types:
| Type | Handles |
|---|---|
FlexInt |
42 or "42" |
FlexFloat |
9.5, 42, or "9.5" |
FlexBool |
true or "true" |
FlexTimestamp |
1411833600 or false |
NullableFlexInt |
42, "42", "", or null |
Access the parsed value via .Value and check if it was present via .Set.
- Every endpoint requires a club API key as a path segment — this is handled automatically by the client
- Access to specific endpoints may need manual enablement by league administration
- The
birthdateUNIX timestamp field on roster players is documented as faulty — usebirthdate_ymdinstead - SwissTiming livedata files can return different payload shapes depending on the file; use
GetSwissTimingRawfor non-standard formats
Create a git tag with semantic versioning:
git tag -a v0.1.0 -m "Release v0.1.0"- Push the tag to trigger the release:
git push origin v0.1.0
MIT