Basic Auth
A guide on how to use Basic Auth for authenticating to our REST APIs.
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 for access control.
Prerequisites
A Service Account 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.
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())// 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();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))
}
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_SECRETLast updated