# Basic Auth

## Overview

Basic Auth is supported in most request libraries and is often as simple as adding a username- and password parameter. To get you up and running quickly, we present a few language-specific methods by fetching a list of projects available from the REST API using a [Service Account](/service-accounts/creating-service-accounts.md) for access control.

{% hint style="info" %}
We don't recommend using this authentication flow for production use, the main use for Basic Auth is for quick exploration and experimentation.
{% endhint %}

## Prerequisites

A [Service Account](/service-accounts/creating-service-accounts.md) must be created in the organization before continuing.

## Code Sample

The following examples sends a GET request to list available spaces in your organization. See the API Reference for all available API calls.

{% tabs %}
{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
import os
import requests  # pip install requests

# Inputs
key_id = '<service account key id>'
sercret = '<service account secret>'

if __name__ == '__main__':
    # Send GET request to endpoint of choice with Basic Auth authentication.
    spaces = requests.get(
        url='https://app.neowit.io/api/space/v1/space',
        auth=(key_id, secret),
    )

    # Print response contents.
    print(spaces.json())
```

{% endcode %}
{% endtab %}

{% tab title="Node.js" %}
{% code lineNumbers="true" %}

```javascript
// modules
const axios = require('axios').default; // npm install axios

// Inputs
const keyID = '<service account key id>';
const secret = '<service account secret>';

async function main() {
    // Send GET request to endpoint of choice with Basic Auth authentication.
    const response = await axios({
        method: 'GET',
        url: 'https://app.neowit.io/api/space/v1/space',
        auth: {
            username: keyId,
            password: secret,
        }
    })

    // Print response contents.
    console.log(JSON.stringify(response.data, null, 2))
}
main();
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"
)
// Inputs
;
const (
	spacesURL = "https://app.neowit.io/api/space/v1/space"
	keyID = "<service account key id>"
	secret = "<service account secret>"
)

func main() {
	// Create a custom http Client with timeout.
	client := &http.Client{Timeout: time.Second * 3}

	// Create the request object with method, URL, but no optional body.
	req, err := http.NewRequest("GET", spacesURL, nil)
	if err != nil {
		log.Fatal(err)
	}

	// Set the request's Authorization header to use HTTP Basic Authentication.
	req.SetBasicAuth(keyID, secret)

	// Send an HTTP request and return an HTTP response.
	response, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer response.Body.Close()

	// Convert response body to map.
	var body map[string]interface{}
	if err = json.NewDecoder(response.Body).Decode(&body); err != nil {
		log.Fatal(err)
	}

	// Pretty print the response body.
	prettyBody, _ := json.MarshalIndent(body, "", "    ")
	fmt.Println(string(prettyBody))
}

```

{% endcode %}
{% endtab %}

{% tab title="cURL" %}

```bash
export NW_SERVICE_ACCOUNT_KEY_ID="<service account key id>"
export NW_SERVICE_ACCOUNT_SECRET="<service account secret>"

curl -X GET "https://app.neowit.io/api/space/v1/space" \
    -H "accept: application/json" \
    -u $NW_SERVICE_ACCOUNT_KEY_ID:$NW_SERVICE_ACCOUNT_SECRET
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.neowit.io/rest-api/authentication/basic-auth.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
