API v4 - Commit history until given commit

We’re trying to query all latest commits in a given branch of a repository, that were made after a given commit (we have the ID and SHA of this commit). But “after” and “before” in the commit history option are cursors and do not accept an ID or SHA. How can we perform this query based on the ID or SHA of the target commit instead?

We can run this query really easily with the v3 REST API, but we only need two fields so fetching all the (extensive) commit data for every commit is overkill, hence our need to switch to the v4 GraphQL API.

1 Like

Hey @woubuc!

Just to make sure we can find the right solution, would you mind sharing the v3 API query that gives you the information that you’re looking for? That should help us dial in what options exist in v4, and/or scope out what would be needed to add that functionality if it doesn’t exist. 


1 Like

Apparently this was a misunderstanding of the docs - the “SHA” parameter doesn’t actually do what we would need it to do, rather it goes in the opposite direction.

Essentially, what we need is an “until” parameter that would list the most recent commits in the history, up until the given commit (identified by SHA). After some testing it seems that this isn’t currently possible.

So except for manually filtering the results on our end, is there a way to perform this query with the current APIs?

Hey @woubuc,

Good to know! I’m curious: it might take two requests, but would you be able to fetch the cursor in GraphQL for the recent SHA, and then make a second request looking at the “before” of that cursor? It might not be the most elegant thing, but I think it might accomplish what you’re looking for?

Let me know if that works!