How are we supposed to programmatically build dashboards using the API

I’m trying to automate building some dashboards and I’m running into small hurdle after hurdle and I’m wondering what the developer workflow is supposed to be like.

What I expect

I expected that I would be able to “Copy JSON” from a dashboard and then push that to an API and create a dashboard. Easy, right?

What I’ve encountered

GraphQL is not JSON. How is a programmatic language supposed to interact with the API without tons of string replacement?

  • When you copy the dashboard JSON, it’s not actually valid for the GraphQL post because you have to remove the strings from the “permissions” field
  • When I finally found the NerdGraph documentation for creating a dashboard, I realized there’s a ton of non-json at the end of the GraphQL response. It’s not valid JSON, so I can’t encode/decode it in my language (GoLang) to easily automate it

Using the other NR-provided mechanisms don’t seem to work either

  • After I figured out the GraphQL language the browser liked, I used “tools” to copy the data as a cURL. Well, the formatting of this is very different than the dashboard I have; you have to include specific non-json preambles before the actual JSON dashboard (which we already discussed isn’t valid json). You have to start with {"query":"mutation {\n dashboardCreate. What kind of wild syntax is that??

  • The newrelic-client-go library is outdated and won’t work

  • I tried to interact with the NR CLI, but the syntax is also very janky and can’t be easily parsed programmatically (more wild non-json syntax)
    newrelic nerdgraph query 'mutation { dashboardCreate(accountId: ***, dashboard: { *pseudo-json*

So, my question is, what is the expected developer workflow to programmatically build dashboards?

1 Like

Hi @brett.barrett You should be able to import/export a dashboard to JSON. You will need to edit the json to change the accountId. Make sure the dashboard limits are not violated as noted below as an error will be returned when importing if they are violated:

Maximum number of pages in a dashboard - 20
Maximum length of a dashboard name - 255
Maximum length of a dashboard description - 1024

The doc below explains the process a bit more.

NerdGraph tutorial: Move dashboards to other accounts

1 Like

Hey there,

Thank you for your response. How can you do this through the API though, and not while fuddling around in NerdGraph? I would like to write an application to automatically create and modify dashboards for me, but when using NerdGraph API, you have to provide non-JSON with the JSON and it’s really messy.

@brett.barrett - You can obtain the CURL command from NerdGraph through the Tools dropdown as shown below:

Hey there,

I feel like my initial request is not being heard.

what is the expected developer workflow to programmatically build dashboards?

Sure, I can download the cURL, which I have, but then it’s not easy to add tiles to this without writing very specific non-json code. This isn’t scalable when I went to build dozens of dashboards with dozens of tiles.

1 Like

Hi @brett.barrett as far as another option, developers do seem to leverage terraform to automate scenarios like this, I’m unsure if that is a possible route for you. https://developer.newrelic.com/terraform/ can provide a lot of insight there.