Need to save generated Bearer Token to a local file on a schedule

I have a collection that generates a bearer token for Microsoft D365. What I would like to be able to do is get it to save the “Raw” output that I get to a file automatically. Then is is possible to schedule this to work and create the file on a regular basis?

Hope you can help.

Many Thanks

Why do you want to do this? This sounds like very bad practice and a major security hole.

The reason for this is that we currently use a token on our EDI server to download data and create EDI. The EDI software does the same job, it gets the TOKEN and creates a file every hour as it only lasts an hour. However we have an issue with the EDI software where every two or three weeks, it takes too long to get the token, can be 10-20 minutes if it works at all, and then it brings down the whole EDI system, this can go on for a week or so. However during this period I have to run my collection to get a new token and save it in a file manually so the EDI system can access data. Unfortunately the software company who do the EDI software have been bought out and although they have recognised the issue, have not fixed it in the 8 months I have been waiting. So this is for when the system is failing as a backup. Obviously I am looking at new EDI software.