I am looking to implement a Zoho ticketing dashboard within Grafana, and I have a few questions regarding the integration.
- Integration with Zoho API:
I need to utilize Zoho API calls that require a code, client ID, and client secret to generate an access token and refresh token. The access token expires every 60 minutes, requiring the need for a middleware to refresh it when any of the APIs returns a 401 error.
Additionally, the integration needs to run through Grafana’s backend plugin, as the endpoint will throw a CORS error from the frontend due to Grafana having a separate OAuth for frontend applications, which does not meet the use case.
- Storage of Tokens:
My challenge lies in determining where to store the access token and refresh token securely. Initially, I considered saving them by creating two read-only inputs in the Query editor and exposing an endpoint throughCallResource
to retrieve the access token for the first time and save it directly as a query.
However, I am not sure how to update the access token once it has been refreshed. What is the best approach to achieve this functionality?
- Example cURLs:
Here are the example cURL requests for obtaining and refreshing the tokens. I have obfuscated the sensitive data for security purposes:
Create Token
curl --location --request POST 'https://accounts.zoho.com.au/oauth/v2/token?code=<code>&grant_type=authorization_code&client_id=<client_id>&client_secret=<client_secret>&scope=Desk.tickets.READ'
Refresh Token
curl --location --request POST 'https://accounts.zoho.com.au/oauth/v2/token?grant_type=refresh_token&client_id=<client_id>&client_secret=<client_secret>&refresh_token=<refresh_token>'
Could you please guide the best practices for implementing this within Grafana’s backend?
Also while calling the CallResource
method from the ConfigEditor using getBackendSrv().fetch
, I noticed it’s calling the CheckHealth
method as well. Is there a way to prevent this? Cause I wanted the check health to be called after generating the tokens.