I'd like to do three things using a read-only access token, so that there is no need for the webpage user to provide Gitlab authentication. I must submit a GET request using the access token in the header, and haven't quite figured out how to handle the response in Javascript.
- Read the contents of a specific .JSON file in the artifacts path, and assign to a variable
- Trigger a download of a specific .XLSX file in the artifacts path, and save to disk
- Trigger a download of the full artifacts archive .ZIP, and save to disk
My code
var myHeader = new Headers();
myHeader.append("PRIVATE-TOKEN", accessToken);
var myInit = {
method: 'GET',
headers: myHeader
};
var myRequest = new Request(artifactPath, myInit);
// response?
Documentation
Guidance provided for 1 and 2:
GET /projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=name
curl --location --header "PRIVATE-TOKEN: <your_access_token>"
"https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/master/raw/some/release/file.pdf?job=pdf"
Guidance provided for 3:
GET /projects/:id/jobs/artifacts/:ref_name/download?job=name
curl --header "PRIVATE-TOKEN: <your_access_token>"
"https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/master/download?job=test"
I'm under the impression that Ajax would help, which I have never used. All viable simplicity would be very much appreciated!