Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow raw api requests #71

Open
mblaschke-daimlertruck opened this issue Jan 30, 2024 · 1 comment
Open

Allow raw api requests #71

mblaschke-daimlertruck opened this issue Jan 30, 2024 · 1 comment

Comments

@mblaschke-daimlertruck
Copy link

Is your feature request related to a problem?
Currently only prebuild APIs can be used with this client. Datasources also have own endpoints which are currently not useable.

Describe the solution you'd like
Add a function to send own API requests to Grafana

Describe alternatives you've considered
Forking is not a good idea

Additional context
eg. to trigger the subscription list of the grafana-azure-monitor-datasource using API /api/datasources/{uid}/resources/azuremonitor/subscriptions

@safaci2000
Copy link
Contributor

I ended up doing this for some unsupported calls:

https://github.com/esnet/gdg/blob/master/internal/api/extended.go

Then, to use it:

var result []*models.UserOrgDTO

req := extended.getRequestBuilder().
	Path("api/user/orgs").
	ToJSON(&result).
	Method(http.MethodGet)

In this case i'm using the OpenAPI models but you can place it with anything you like...

All you really need is something like this:

	req := requests.URL(extended.grafanaCfg.URL)
	if extended.grafanaCfg.APIToken != "" {
		req.Header("Authorization", "Bearer "+extended.grafanaCfg.APIToken)
	} else {
		req.BasicAuth(extended.grafanaCfg.UserName, extended.grafanaCfg.Password)
	}

then use the req entity to build your call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants