401 Unauthorized error when trying to display images on my website
Hello I'm trying to make a gallery with the images that I have in cloudinary using React. I have checked out the Admin API reference and came out with this code:
let myHeaders = new Headers();
myHeaders.append("Authorization", "Basic " + btoa(apiKey + ":" + apiSecret));
myHeaders.append("Content-Type", "application/json");
let requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow',
mode: 'no-cors'
};
const getImages = () => {
fetch("https://api.cloudinary.com/v1_1/<cloudname>/resources/image", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
};
The problem is that when I call the getImages() function I keep getting a 401 error:
I also tried it on Postman and it do works. I do get de JSON with all the resources.
Thank you!!!
0
-
Hi Pablo,
The Admin API requests require sending the API Secret which should never be exposed on the client-side, therefore the Admin API is only available via our server-side SDKs.
If you would like to get a list via your client-side, you can use this feature to list resources by tag: https://cloudinary.com/documentation/advanced_url_delivery_options#client_side_asset_lists
Please let us know if you have any further questions,
Thanks,
Michal
0
Post is closed for comments.
Comments
1 comment