Instead of raw ‘fetch’, use the helper plugin…
import { getFetchClient } from '@strapi/helper-plugin';
import pluginId from '../../pluginId';
const handleDownload = async () => {
try {
const { get } = getFetchClient();
const response = await get(`/${pluginId}/export`);
// File downloaded successfully - use response.data
} catch (error) {
// Handle error scenario
}
};
The helper plugin will automate adding the necessary bearer token for the user’s admin session. I don’t know how you would acquire that from the strapi instance object but you could always look at the helper plugin code if you prefer to roll your own ‘fetch’.