Unable to decode req.Body in CallResource function


I am trying to implement a custom HTTP call for variable substitution with type Query in datasource-backend-sdk-go plugin.
Followed the steps mentioned in this article and was able to capture the query input from the Variables page.
I have overridden metricFindQuery method in datasource.ts file and made call to backend using postResource() method.
Here’s how my metricFindQuery and CallResource method looks

async metricFindQuery(query: string, options?: any) {
 const response = await this.postResource('facet-query', { query: query, test: 'val' });

func (d *DataSetDatasource) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
        var fm filterModal
	err1 := json.Unmarshal(req.Body, &fm)

type filterModal struct {
    query string `json:"query"`

So, the issue is, the documentation says req.Body should have the data that has been passed through postResource method. But when I try to access the data, it shows an encoded string in bytes format, and Unmarshall always returns empty.

Any help on this is appreciated

In case anyone drops in from Google, the issue was that the frontend URL-encoded the JSON before sending it to the resource handler, which meant that the json package couldn’t decode the payload.

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