- Fittingbox - Customer Help Center
- Eyewear Digitization
- API Management
How to download an asset from Widen API?
You first need to search for your file and store the download link from the search response under the _links => download properties of the item.
var myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer fittingbox/********************************"); var requestOptions = { method: 'GET', headers: myHeaders }; fetch("https://api.widencollective.com/v2/assets/search?query=fn:{00293654786012_86.tif}&expand=metadata,embeds", requestOptions) .then(response => response.json()) .then(result => { fetch(result.items[0]._links.download) .then(res => res.blob()) .then(blob => { var file = window.URL.createObjectURL(blob); window.location.assign(file); }); }) .catch(error => console.log('error', error));
How to rename the file?
If you want to rename your file, you can force the download and change the filename adding this line:
a.download = "yourNewName.tif";
var myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer fittingbox/********************************"); var requestOptions = { method: 'GET', headers: myHeaders }; fetch("https://api.widencollective.com/v2/assets/search?query=fn:{00293654786012_86.tif}&expand=metadata,embeds", requestOptions) .then(response => response.json()) .then(result => { fetch(result.items[0]._links.download) .then(res => res.blob()) .then(blob => { var url = window.URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; a.download = "yourNewName.tif"; document.body.appendChild(a); a.click(); a.remove(); }); }) .catch(error => console.log('error', error));