Published Function has no access to Dataset

I have created a custom user defined function that grabs parameters from different Ontologies and create a pdf file.

I am able to load the pdf file onto a Dataset when i run the code in Local Preview but once i publish the function it throws the below error

:cross_mark: File upload failed: { “errorCode”: “PERMISSION_DENIED”, “errorInstanceId”: “209fe377-269b-4abb-8ae2-06b584823d8a”, “errorName”: “ApiUsageDenied”, “parameters”: { “missingScope”: “api:usage:datasets-write” } } :light_bulb: Dataset RID: ri.foundry.main.dataset.21273352-6f8f-4ef7-9242-0d2df31ebb90 :magnifying_glass_tilted_left: Check dataset permissions and API access

This inturn is affecting me to call the function on a workshop and trigger an event to load the data into a pdf and store them into a dataset.

Thanks in advance