<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HTTP API examples on Grafana Labs</title><link>https://grafana.com/docs/grafana/v12.4/developer-resources/api-reference/http-api/examples/</link><description>Recent content in HTTP API examples on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v12.4/developer-resources/api-reference/http-api/examples/index.xml" rel="self" type="application/rss+xml"/><item><title>API Tutorial: Create Service Account tokens and dashboards for an organization</title><link>https://grafana.com/docs/grafana/v12.4/developer-resources/api-reference/http-api/examples/create-api-tokens-for-org/</link><pubDate>Fri, 03 Apr 2026 20:44:05 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/developer-resources/api-reference/http-api/examples/create-api-tokens-for-org/</guid><content><![CDATA[&lt;h1 id=&#34;create-service-account-tokens-and-dashboards-for-an-organization&#34;&gt;Create Service Account tokens and dashboards for an organization&lt;/h1&gt;
&lt;p&gt;Use the Grafana API to set up new Grafana organizations or to add dynamically generated dashboards to an existing organization.&lt;/p&gt;
&lt;h2 id=&#34;authentication&#34;&gt;Authentication&lt;/h2&gt;
&lt;p&gt;There are two authentication methods to access the API:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Basic authentication: A Grafana Admin user can access some parts of the Grafana API through basic authentication.&lt;/li&gt;
&lt;li&gt;Service Account tokens: All organization actions can be accessed through a Service Account token. A Service Account token is associated with an organization. It can be used to create dashboards and other components specific for that organization.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;how-to-create-a-new-organization-and-a-service-account-token&#34;&gt;How to create a new organization and a Service Account Token&lt;/h2&gt;
&lt;p&gt;The task is to create a new organization and then add a Token that can be used by other users. In the examples below which use basic auth, the user is &lt;code&gt;admin&lt;/code&gt; and the password is &lt;code&gt;admin&lt;/code&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/http_api/org/#create-organization&#34;&gt;Create the org&lt;/a&gt;. Here is an example using curl:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl -X POST -H &amp;#34;Content-Type: application/json&amp;#34; -d &amp;#39;{&amp;#34;name&amp;#34;:&amp;#34;apiorg&amp;#34;}&amp;#39; http://admin:admin@localhost:3000/api/orgs&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This should return a response: &lt;code&gt;{&amp;quot;message&amp;quot;:&amp;quot;Organization created&amp;quot;,&amp;quot;orgId&amp;quot;:6}&lt;/code&gt;. Use the orgId for the next steps.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Optional step. If the org was created previously and/or step 3 fails then first 
    &lt;a href=&#34;/docs/grafana/v12.4/http_api/org/#add-user-in-organization&#34;&gt;add your Admin user to the org&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl -X POST -H &amp;#34;Content-Type: application/json&amp;#34; -d &amp;#39;{&amp;#34;loginOrEmail&amp;#34;:&amp;#34;admin&amp;#34;, &amp;#34;role&amp;#34;: &amp;#34;Admin&amp;#34;}&amp;#39; http://admin:admin@localhost:3000/api/orgs/&amp;lt;org id of new org&amp;gt;/users&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/http_api/user/#switch-user-context-for-signed-in-user&#34;&gt;Switch the org context for the Admin user to the new org&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl -X POST http://admin:admin@localhost:3000/api/user/using/&amp;lt;id of new org&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../serviceaccount/#create-service-account&#34;&gt;Create a Service Account&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl -X POST -H &amp;#34;Content-Type: application/json&amp;#34; -d &amp;#39;{&amp;#34;name&amp;#34;:&amp;#34;test&amp;#34;, &amp;#34;role&amp;#34;: &amp;#34;Admin&amp;#34;}&amp;#39; http://admin:admin@localhost:3000/api/serviceaccounts&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../serviceaccount/#create-service-account-tokens&#34;&gt;Create a Service Account token&lt;/a&gt; for the service account created in the previous step:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl -X POST -H &amp;#34;Content-Type: application/json&amp;#34; -d &amp;#39;{&amp;#34;name&amp;#34;:&amp;#34;test-token&amp;#34;}&amp;#39; http://admin:admin@localhost:3000/api/serviceaccounts/&amp;lt;service account id&amp;gt;/tokens&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This should return a response:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;http&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-http&#34;&gt;HTTP/1.1 200
Content-Type: application/json

{
  &amp;#34;id&amp;#34;: 7,
  &amp;#34;name&amp;#34;: &amp;#34;test-token&amp;#34;,
  &amp;#34;key&amp;#34;: &amp;#34;eyJrIjoiVjFxTHZ6dGdPSjg5Um92MjN1RlhjMkNqYkZUbm9jYkwiLCJuIjoiZ3JhZmFuYSIsImlkIjoxfQ==&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Save the key returned here in your password manager as it is not possible to fetch again it in the future.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;how-to-add-a-dashboard&#34;&gt;How to add a dashboard&lt;/h2&gt;
&lt;p&gt;Using the Token that was created in the previous step, you can create a dashboard or carry out other actions without having to switch organizations.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v12.4/http_api/dashboard/#create-update-dashboard&#34;&gt;Add a dashboard&lt;/a&gt; using the key (or bearer token as it is also called):&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl -X POST --insecure -H &amp;#34;Authorization: Bearer eyJrIjoiR0ZXZmt1UFc0OEpIOGN5RWdUalBJTllUTk83VlhtVGwiLCJuIjoiYXBpa2V5Y3VybCIsImlkIjo2fQ==&amp;#34; -H &amp;#34;Content-Type: application/json&amp;#34; -d &amp;#39;{
  &amp;#34;dashboard&amp;#34;: {
    &amp;#34;id&amp;#34;: null,
    &amp;#34;title&amp;#34;: &amp;#34;Production Overview&amp;#34;,
    &amp;#34;tags&amp;#34;: [ &amp;#34;templated&amp;#34; ],
    &amp;#34;timezone&amp;#34;: &amp;#34;browser&amp;#34;,
    &amp;#34;rows&amp;#34;: [
      {
      }
    ],
    &amp;#34;schemaVersion&amp;#34;: 6,
    &amp;#34;version&amp;#34;: 0
  },
  &amp;#34;overwrite&amp;#34;: false
}&amp;#39; http://localhost:3000/api/dashboards/db&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you export a dashboard for sharing externally using the Share &amp;gt; Export menu in the Grafana UI, you cannot import that dashboard. Instead, click &lt;strong&gt;View JSON&lt;/strong&gt; and save it to a file or fetch the JSON output through the API.&lt;/p&gt;&lt;/blockquote&gt;
]]></content><description>&lt;h1 id="create-service-account-tokens-and-dashboards-for-an-organization">Create Service Account tokens and dashboards for an organization&lt;/h1>
&lt;p>Use the Grafana API to set up new Grafana organizations or to add dynamically generated dashboards to an existing organization.&lt;/p></description></item><item><title>cURL examples</title><link>https://grafana.com/docs/grafana/v12.4/developer-resources/api-reference/http-api/examples/curl-examples/</link><pubDate>Fri, 03 Apr 2026 20:44:05 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/developer-resources/api-reference/http-api/examples/curl-examples/</guid><content><![CDATA[&lt;h1 id=&#34;curl-examples&#34;&gt;cURL examples&lt;/h1&gt;
&lt;p&gt;This page provides examples of calls to the Grafana API using cURL.&lt;/p&gt;
&lt;p&gt;The most basic example for a dashboard for which there is no authentication. You can test the following on your local machine, assuming a default installation and anonymous access enabled, required:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;curl http://localhost:3000/api/search&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Here&amp;rsquo;s a cURL command that works for getting the home dashboard when you are running Grafana locally with 
    &lt;a href=&#34;/docs/grafana/v12.4/setup-grafana/configure-access/configure-authentication/#basic-auth&#34;&gt;basic authentication&lt;/a&gt; enabled using the default admin credentials:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;curl http://admin:admin@localhost:3000/api/search&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To pass a username and password with 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/roles-and-permissions/access-control/manage-rbac-roles/&#34;&gt;HTTP basic authorization&lt;/a&gt;, encode them as base64.
You can&amp;rsquo;t use authorization tokens in the request.&lt;/p&gt;
&lt;p&gt;For example, to 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/roles-and-permissions/access-control/manage-rbac-roles/&#34;&gt;list permissions associated with roles&lt;/a&gt; given a username of &lt;code&gt;user&lt;/code&gt; and password of &lt;code&gt;password&lt;/code&gt;, use:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;curl --location &amp;#39;&amp;lt;grafana_url&amp;gt;/api/access-control/builtin-roles&amp;#39; --user &amp;#39;user:password&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="curl-examples">cURL examples&lt;/h1>
&lt;p>This page provides examples of calls to the Grafana API using cURL.&lt;/p>
&lt;p>The most basic example for a dashboard for which there is no authentication. You can test the following on your local machine, assuming a default installation and anonymous access enabled, required:&lt;/p></description></item></channel></rss>