I am attempting create a button for downloading a csv file when an item is selected from a dropDown list. Ive done this before but the response returned this time is different than what im use to. I could use some help understanding how to format things to correctly download and display the data in a csv file when the api is hit.
so far I have an onClick function that looks like this:
const onDownloadReport = (type) => {
const org = type === "All" ? "" : type;
api.providerPayroll
.reports({
date: activePayPeriod,
org: org,
})
.then((res) => {
window.open("data:text/csv;charset=utf-8," + res);
});
};
this works to download the csv file. However it doesnt contain the actual data in the response it shows null in the csv. When i try to console out the res
I get null as well. Im not sure what Im missing here for capturing the response.
If I need to add more information on this please let me know.
from Downloading the response from an api call as a csv onClick
No comments:
Post a Comment