VolkovLabs / business-forms

The Business Forms panel is a conceptually new plugin for Grafana. It is the first plugin that allows inserting and updating application data, as well as modifying configuration directly from your Grafana dashboard.
https://docs.volkovlabs.io
Apache License 2.0
86 stars 10 forks source link

Infinity DataSource Nested Object payload #549

Open asergeant01 opened 1 week ago

asergeant01 commented 1 week ago

I am following this blog post.

My Update Request "Create Payload" is basically:

var jsonData = {
  "createdBy": createdBy,
  "startsAt": startTime,
  "endsAt": endTime,
  "comment": comment,
  "matchers": matchers
}

return jsonData;

Whereby matchers is a further array of objects that is dynamically build based from form data.

My Query Editor "URL options" body content is the following:

{
  "createdBy": "${payload.createdBy}",
  "startsAt": "${payload.startsAt}",
  "endsAt": "${payload.endsAt}",
  "comment": "${payload.comment}",
  "matchers": ${payload.matchers}
}

This produces the following output on the request:

"executedQueryString": "###############
## URL
###############

https://<HIDDEN>

###############
## Curl Command
###############

curl -X 'POST' -d '{ 
\"createdBy\": \"alan\",
\"startsAt\": \"Thu Nov 14 2024 11:24:27 GMT+0000 (Greenwich Mean Time)\",
\"endsAt\": \"Sat Nov 16 2024 11:24:27 GMT+0000 (Greenwich Mean Time)\",
 \"comment\": \"Alan Test\",
\"matchers\": [object Object],[object Object],[object Object],[object Object]
}' -H 'Accept: application/json;q=0.9,text/plain' -H 'Authorization: Basic xxxxxxxx' -H 'Content-Type: application/json' 'https://<HIDDEN>'"

I would expect it to parse this or alternatively, provide the option to let the developer build the full body in "create payload" and return the JSON.stringify which can be inserted into the body content using ${payload}

mikhail-vl commented 1 week ago

@asergeant01 Thank you for bringing it to our attention.

We discussed it with the team and will look into improving objects in the upcoming release.

asergeant01 commented 1 week ago

@mikhail-vl Awesome. Thanks. Until such times and for anyone else finding this, I was able to work around using the following:

var jsonData = {
  "createdBy": createdBy,
  "startsAt": startTime.toISOString(),
  "endsAt": endTime.toISOString(),
  "comment": comment,
  "matchers": JSON.stringify(matchers).replaceAll('\"', '\\"')
}
mikhail-vl commented 1 week ago

@asergeant01 Thank you for providing temporary solution.