I’m assuming you would like to do this through the REST API, since the previous comment giving you the Java API wasn’t helpful.
There is a REST endpoint you can get this from: https://docs.atlassian.com/bitbucket-server/rest/5.10.1/bitbucket-rest.html#idm45736094257136
You’ll want to include the
until query params as the two branches you want to diff between, so you will do a GET on something like this:
Hope this helps!