getBackendSrv().datasourceRequest error, but data is available

I am following the documentation to create a simple datasource plugin, using the backendsrv as a proxy with authentication tokens configured and working to consult an in house REST GET API.

The relevant code from datasource.ts:

async doRequest(query: MyQuery) {
    console.log(query.minInterval);

    let url = `${this.url}/${query.path}/${query.arch}/`;
    if (!query.path || query.path === 'list') {
      url += query.listType;
    } else if (query.path === 'cfg') {
      url += query.getHash;
    }

    console.log('URL: ' + url);

    const result = await getBackendSrv().datasourceRequest({
      url: url + '/',
      method: 'GET',
    });

    return result;
  }

  async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {

    let promises = options.targets.map((query) => {
      this.doRequest(query).then((result) => {
        const frame = new MutableDataFrame({
          refId: query.refId,
          fields: [
            { name: 'Time', type: FieldType.time },
            { name: 'tag', type: FieldType.string },
            { name: 'hash', type: FieldType.string },
            { name: 'description', type: FieldType.string },
          ],
        });

        const data = result.data;
        if (data) {
          data.forEach((point: any) => {
            frame.appendRow([
              new Date(point.ts),
              point.tag,
              point.hash,
              point.description,
            ]);
          });
        }

        console.log(frame);

        return frame;
      });
    });

    return Promise.all(promises).then((data) => ({ data }));
  }

When I send a request, I get the following error:

URL: /api/datasources/proxy/2/scrblist/e32/cfg
hostReportError.js:3 Uncaught TypeError: Cannot use 'in' operator to search for 'fields' in undefined
    at j (processDataFrame.ts:278)
    at S (runRequest.ts:170)
    at k (runRequest.ts:197)

Although the response data is correct. This error causes an error in the query result in the panel is empty (0 results). It would seem there is an error in the query passed to the datasourceRequest function, but I can’t see it.

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