Get file archive API returns 403

Hello Folks,

I am trying to fetch the repository archive via java code for API: GET /projects/:id/repository/archive
as documented in

I am using PAT for authentication. This API returns a 403. However i am able to call many other APIs to fetch Repositories, branches and they just as expected. Wondering if there is anything specific to this API that i am missing. A call via POSTMAN http client for this API works just fine too.

The URL i am calling is -
with PAT key as a header parameter.

Here is my sample java code:
Building the URL:
private URL makeGitLabGetArchiveUrl(String endPoint, String version, String repositoryId, String branchName) {
try {
List queryParams = new ArrayList<>();
queryParams.add(new BasicNameValuePair(“sha”, branchName));
URIBuilder uriBuilder = new URIBuilder(endPoint + “/api/” + version + “/projects/” + repositoryId + “/repository/”);
} catch (URISyntaxException | MalformedURLException e) {
throw new RenderableException(
ErrorCode.InternalError, “URL is malformed. endPoint:%s, version:%s, repoId:%s”, endPoint, version, repositoryId);

The Http GET call:
private String doHttpGet(URL url, String personalAccessToken) {
StringBuffer content = new StringBuffer();
Failsafe.with(CONNECTION_RETRY).run(() -> {
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
// con.setRequestProperty(“Content-Type”, “application/zip”);
con.setRequestProperty(“PRIVATE-TOKEN”, personalAccessToken);

        try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
            String inputLine;
            while ((inputLine = in.readLine()) != null) {

    return content.toString();

Thanks in advance for your help.