Download to /tmp

I’m trying to download (to /tmp) a json from an endpoint that requires authentication. But I’m getting “HTTPErrorResponse code 403 (Unauthorized)” message when submitting the get. When I do the same thing via a get using Axios I get it. How solve this?

DOWNLOAD URL
https://login:password@mydomain.com/rest/accomplishedVisit?currentPage=0&pageSize=500&startDate=2021-08-01&endDate=2021-08-12&zfVisitTypeIds=5107,9774&zfVisitResultIds=4793
STEP CODE
const fs = require(“fs”);
const { default: got } = await import(“got”);
const stream = require(“stream”);
const { promisify } = require(“util”);
const pipeline = promisify(stream.pipeline);
await pipeline(
got.stream(params.downloadURL),
fs.createWriteStream(params.filePath)
);

Are you using the parameter with axios? auth: {
username: ‘janedoe’,
password: ‘s00pers3cret’
},

Axios translates that for you in a request with an HTTP Basic Authentication, which needs to be set that the header object of your request. Depending on the server you may need to enconde into string 64 your credentials.

From axios docs:

// auth indicates that HTTP Basic auth should be used, and supplies credentials.
// This will set an Authorization header, overwriting any existing
// Authorization custom headers you have set using headers.
// Please note that only HTTP Basic auth is configurable through this parameter.
// For Bearer tokens and such, use Authorization custom headers instead.
Is you still require the crendetials to be sent in the URL, that might not be supported in the host you are sending the request against because it is a deprecated way for doing so:
HTTP authentication - HTTP | MDN (mozilla.org)