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 https://docs.gitlab.com/ee/api/repositories.html#get-file-archive

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 - https://gitlab.com/api/v4/projects/18346998/repository/archive.zip
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/archive.zip”);
return uriBuilder.build().toURL();
} 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.setRequestMethod(“GET”);
// con.setRequestProperty(“Content-Type”, “application/zip”);
con.setRequestProperty(“PRIVATE-TOKEN”, personalAccessToken);
con.setConnectTimeout(5000);
con.setReadTimeout(5000);

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

    return content.toString();
}

Thanks in advance for your help.

Thanks,
Venkata