Accessing query properties when making API call

When calling an API for a datasource plugin.
All the examples of calling an API just pass the whole query to params.

If i’m calling an existing API and need to customise my params how do I access the properties of the query eg startTime, endTime etc
query.endTime does not work and i’m not sure of how to access the properties inherited from DataQueryRequest or do I need to expose them somehow in MyQuery ??
eg

  async doRequest(query: MyQuery) {
    const globalParams = {
      dateFrom: query.startTime * 1000,
      dateTo: query.endTime * 1000,
      frequency: 'raw',
    };
    const result = await getBackendSrv().datasourceRequest({
      method: 'GET',
      url: 'https://existing.api.url',
      params: globalParams,
    });

    return result;
  }

OK partial answer to my own question. in the async query function you can get to them though options eg options.range.from

Sounds you found what you were looking for. Just like you said, the DataQueryRequest object in the query method provides context about the query.

Since you said it’s a “partial” answer, is there something you’re missing still?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.