How to Use JSON API Datasource with Bearer Token

I am using the JSON API datasource plugin to pull data from a third party system. The API requires a bearer token for authorization, which expires after 6 hours. I am looking for a solution for automating the update of the token before it expires. I have written a script that acquires a new token and updates the datasource in Grafana via the datasources API. I can see the script is executing, and Grafana is returning a “Datasource updated” response. However, the token inserted via the API is not working, and I am getting auth errors. I can generate the same token and enter it into the datasource manually, and it works. Any idea why is is not working through the API?