These are provided only as basic examples to build upon when crafting a solution that best fits your environment and needs.
By no means is anything here to be taken as a best practice suggestion.
I would suggest looking at the API authentication options presented at the link below, by user macnotes rather then the methods given in any of these examples.
https://github.com/macnotes/jamfscripts/tree/main/jamfpro/getJamfApiCredentials