# Basic Auth API Call

**URL:** <https://community.grafana.com/t/basic-auth-api-call/37091>\
**Category:** Authentication\
**Created:** [September 24, 2020, 1:20pm UTC](https://community.grafana.com/t/basic-auth-api-call/37091 "2020-09-24T13:20:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hrodriguez2](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hrodriguez2](https://community.grafana.com/u/hrodriguez2)\
**Post date:** [September 24, 2020, 1:20pm UTC](https://community.grafana.com/t/basic-auth-api-call/37091/1 "2020-09-24T13:20:05Z")

</div>

Hi, I’m just a beginner on Grafana, I would like some example on how to use API to authenticate as Admin using Basic Auth through API call , and then create viewer users with another API call, not sure how should I pass user and password in request or If somehow I need to get a token first and then use it in subsecuent calls, If you could help me with an example of it that would be awsome,

Please Advise,

---

<div class="post-metadata">

**Author:** ![agnestoulet1](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@agnestoulet1](https://community.grafana.com/u/agnestoulet1)\
**Post date:** [September 24, 2020, 4:40pm UTC](https://community.grafana.com/t/basic-auth-api-call/37091/2 "2020-09-24T16:40:22Z")

</div>

Hello,

If you want to use Basic Auth, you need to provide your username and password. The way of providing this information depends on the tool you are using to do the request. Here is an example using cURL (you can also leave the password blank and you will be prompted for the password)

```auto
curl --request POST 'http://grafana.staged-by-discourse.com/api/admin/users' --user "admin:admin" --header 'Content-Type: application/json' --data-raw '{"name":"test","email":"test","login":"test","password":"test"}'

```

If you search on Google the name of your tool and Basic Authentication, you should find more specific examples.

You have all the ways of authenticating to the API [here](https://grafana.com/docs/grafana/latest/http_api/auth/). You can also use a session cookie (that you can retrieve with a login request) or an API Token (that you can generate through Grafana UI).

---

<div class="post-metadata">

**Author:** ![hrodriguez2](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hrodriguez2](https://community.grafana.com/u/hrodriguez2)\
**Post date:** [September 24, 2020, 8:35pm UTC](https://community.grafana.com/t/basic-auth-api-call/37091/3 "2020-09-24T20:35:22Z")

</div>

Maybe I should have started what I want to accomplish here, what I actually want is to embbed grafana dashboards into homemade application, so I need some how send credentials and not showing login page, I hope you can guide me in right direction.

Best Regards,

---

<div class="post-metadata">

**Author:** ![ilaydaislek](https://avatars.discourse-cdn.com/v4/letter/i/9f8e36/32.png) [@ilaydaislek](https://community.grafana.com/u/ilaydaislek)\
**Post date:** [October 1, 2021, 1:34pm UTC](https://community.grafana.com/t/basic-auth-api-call/37091/4 "2021-10-01T13:34:29Z")

</div>

> [@hrodriguez2](#):
>
> t I want to accomplish here, what I actually want is to embbed grafana dashboards into homem

Hello  
if you find the solution, please could u share here too?

---

<div class="post-metadata">

**Author:** ![stefanpetter](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stefanpetter](https://community.grafana.com/u/stefanpetter)\
**Post date:** [December 2, 2021, 3:27pm UTC](https://community.grafana.com/t/basic-auth-api-call/37091/5 "2021-12-02T15:27:04Z")

</div>

I found a solution to use Basic Auth in PowerShell, but the solution should work in any language 🙂

Instead of appending your credentials to the url ([user:pass@example.com](mailto:user:pass@example.com)), you need to base64 encode the user:pass string and use it in the header. My current Powershell Script:

```auto
$credentials = "username:password" # Dont forget the : here
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credentials))

$headersGrafana = @{
    "Authorization" = ("Basic "+$encodedCreds)
    "Content-Type" = "application/json"
}
$urlGrafanaOrganizations = "https://grafana.example.com/api/orgs"

Invoke-RestMethod -Uri $urlGrafanaOrganizations -Method Get -Headers $headersGrafana

```

I hope this work for you too!
