-3

I am trying to get a list of games whose first release was on a given platform. Because I've noticed that if you simply filter for games released on a platform and sort them by release dates, you get games whose original release long predates their re-release on said platform. So, it kind of skews the results, especially when you're trying to have a more chronological history of video games, if that makes sense. I want to completely get rid of re-releases, I guess.

So here's the problem: Using the https://api.igdb.com/v4/games/ endpoint, I tried to post fields *; where first_release_date.platform = 45;, whereas 45 is the ID for the Playstation 4. But it gives me this error upon sending it:

[
    {
        "title": "Invalid Field",
        "status": 400,
        "cause": "Invalid field name: 'first_release_date.platform'"
    }
]

What am I doing wrong here? I mean, I get the error. It says that first_release_date isn't a field that can be used, but the fact of the matter is that I specifically got that field from the doc itself. Am I just using it wrong? What would be the best way to go about this, if it isn't this?

1
  • What is your question about API design? Your question seems to be about how to use an existing API, not designing your own API. Commented May 30 at 18:22

1 Answer 1

0

The docs tells you that first_release_date is a field. A field has no subsequent fields, so it has no platform member. This is an example cURL that should work:

curl 'https://api.igdb.com/v4/games' \
-d 'fields age_ratings,aggregated_rating,aggregated_rating_count,alternative_names,artworks,bundles,category,checksum,collection,collections,cover,created_at,dlcs,expanded_games,expansions,external_games,first_release_date,follows,forks,franchise,franchises,game_engines,game_localizations,game_modes,game_status,game_type,genres,hypes,involved_companies,keywords,language_supports,multiplayer_modes,name,parent_game,platforms,player_perspectives,ports,rating,rating_count,release_dates,remakes,remasters,screenshots,similar_games,slug,standalone_expansions,status,storyline,summary,tags,themes,total_rating,total_rating_count,updated_at,url,version_parent,version_title,videos,websites;' \
-H 'Client-ID: Client ID' \
-H 'Authorization: Bearer access_token' \
-H 'Accept: application/json'

assuming that you have a viable session.

If you want to get only the games whose first release was on a platform, then you will need to use whatever programming language you prefer, loop the results, built up a data structure that groups them by name and platform and find those whose minimum first_release_date is on the platform you seek. Algorithm:

games <- empty_set
for each r in results do
    if not games.contains(name) then
        games.add(name, platforms: [{r.platform: r.first_release_date}])
    else
        games[name].platforms.add({r.platform: r.first_release_date})
    end if
end for
filteredGames <- empty_set
for each g, name in games do
    exists <- false
    minReleaseDate <- now
    theRelease <- now
    for (index <- 0, index < g.platforms.length, index <- index + 1)
        if g.platforms[index].platform = 45 then
            exists <- true
            theRelease <- g.platforms[index].first_release_date
        end if
        if minReleaseDate >= g.platforms[index].first_release_date then
            minReleaseDate <- g.platforms[index].first_release_date
        end if
        if exists and theRelease = minReleaseDate then
            filteredGames.add(name)
        end if
    end for
end for
Sign up to request clarification or add additional context in comments.

5 Comments

Yeah, but that kind of circumvents my point. Is there no way to do this without relying on other programming skills or languages? I thought simply getting a hang of the API would do the trick, but apparently not? I used Postman and already figured out how to query stuff, so yeah, I have a viable session. And, I don't mean to be rude, but I have no clue what any of that means in the second half of your answer.
@kaneyan the second half of the answer is the algorithm to compute the set of games which were first released on that platform. It's a pseudo-code which you can implement with the language of your choice. I did not assume you don't have a viable session, I was just precise in what is needed to make the cURL work. This is a programming site. If you seek to do things non-programmatically, then it's off-topic here. But actually you want to script a cURL via Postman or the like, so your question is a programming question.
@kaneyan as about getting the hang of the API, I'm not a user of this API, so it's possible that there is a solution to your problem without additional programming that I am not aware of, but in the docs page I did not see comprehensive support for custom aggregation. So my position is that it is likely not possible without additional programming and, instead of being frustrated with my answer -as I seem to be the only one who actually wants to help -, maybe you could look into the pseudo-code I have given, invest some effort into understanding it and ask questions about it.
I will try to do that. Thanks a lot.
@kaneyan happy to help. Let me know of the results.

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.