How to send from data from custom plugin

Hi
I’m developing 2 plugins for Grafana.
Plugin 1 is a custom data source that fetches data from a custom API, and the second is a UI representation for this data.
The UI plugin requires a form that updates some server-side data.
Currently, I’m implementing it with a fetch() request.
Is there a way to do that using the custom data source?
can I send form data via Grafana data source?

Thanks

Hi @ilibilibom,

As far as I see, datasource has a datasourceRequest() method. It may be used to POST form data probably. Some kind of:

let options: any = {
  "POST",
  url: "YOUR_URL",
  data: YOUR_FORM_DATA
};

const response = await this.backendSrv.datasourceRequest(options);
const responseData = response.data;

Regards,
V.

Thanks @vsergeyev - I’ll give it a try

How do I access this.backendSrv.datasourceRequest ?
I see that I can import
import { getBackendSrv } from '@grafana/runtime';
but it has no method of datasourceRequest

What worked for me was:

    let options: any = {
      method: "POST",
      url: "https://this-is-a-url",
      data: req
    };
    
    const response = await getBackendSrv().datasourceRequest(options);
    const responseData = response.data;
    console.log('responseData', responseData)

Hope this helps someone :slight_smile:

2 Likes