I am trying to call fetch with credentials to hit a https api
url: https://{apikey}:{password}@{hostname}/admin/api/{version}/{resource}.json
I try this:
var apikey = "mykey";
var password = "mypass";
var hostname = "myhost";
var version = "version";
var resource = "resource";
var API_URL = `https://${apikey}:${password}@${hostname}/admin/api/${version}/${resource}.json`;
fetch(API_URL, {
credentials: "omit"
})
.then((response) => response.json())
.then((data) => console.log(data));
but return this error: Failed to execute 'fetch' on 'Window': Request cannot be constructed from a URL that includes credentials