> ## Documentation Index
> Fetch the complete documentation index at: https://docs.knotapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Learn how to authenticate API requests using HTTP basic authentication with your client_id and secret.

## Overview

Authentication to the API is performed via HTTP basic authentication. Requests made over plain HTTP or without authentication will fail. In each request, pass a base64-encoded string `username:password` as an authorization header. In the [Knot Dashboard](https://dashboard.knotapi.com/developers/keys), you will find your `client_id` and `secret` for the development environment, which you can use as the basic auth `username` and `password` respectively.

When you are ready to go to production, use your production `client_id` and generated `secret` from the [Knot Dashboard](https://dashboard.knotapi.com/developers/keys) for the authentication header.

#### URLs

| Environment | URL                               |
| ----------- | --------------------------------- |
| Development | `https://development.knotapi.com` |
| Production  | `https://production.knotapi.com`  |

## Base64 Encoding

To create the basic authorization header, base64 encode your `client_id` and `secret` in the format `client_id:secret` like below.

<CodeGroup>
  ```typescript TypeScript icon=node-js theme={"system"}
  const clientId = "your_client_id";
  const secret = "your_secret";

  // Combine client_id and secret with a colon
  const credentials = `${clientId}:${secret}`;

  // Base64 encode the credentials
  const encodedCredentials = Buffer.from(credentials).toString('base64');

  // Use in Authorization header
  const authHeader = `Basic ${encodedCredentials}`;
  console.log(authHeader);
  ```

  ```python Python icon=python theme={"system"}
  import base64

  client_id = "your_client_id"
  secret = "your_secret"

  # Combine client_id and secret with a colon
  credentials = f"{client_id}:{secret}"

  # Base64 encode the credentials
  encoded_credentials = base64.b64encode(credentials.encode()).decode()

  # Use in Authorization header
  auth_header = f"Basic {encoded_credentials}"
  print(auth_header)
  ```

  ```go Go icon=golang theme={"system"}
  package main

  import (
      "encoding/base64"
      "fmt"
  )

  func main() {
      clientId := "your_client_id"
      secret := "your_secret"
      
      // Combine client_id and secret with a colon
      credentials := clientId + ":" + secret
      
      // Base64 encode the credentials
      encodedCredentials := base64.StdEncoding.EncodeToString([]byte(credentials))
      
      // Use in Authorization header
      authHeader := "Basic " + encodedCredentials
      fmt.Println(authHeader)
  }
  ```

  ```java Java icon=java theme={"system"}
  import java.util.Base64;
  import java.nio.charset.StandardCharsets;

  public class BasicAuth {
      public static void main(String[] args) {
          String clientId = "your_client_id";
          String secret = "your_secret";
          
          // Combine client_id and secret with a colon
          String credentials = clientId + ":" + secret;
          
          // Base64 encode the credentials
          String encodedCredentials = Base64.getEncoder()
              .encodeToString(credentials.getBytes(StandardCharsets.UTF_8));
          
          // Use in Authorization header
          String authHeader = "Basic " + encodedCredentials;
          System.out.println(authHeader);
      }
  }
  ```

  ```php PHP icon=php theme={"system"}
  <?php
  $clientId = "your_client_id";
  $secret = "your_secret";

  // Combine client_id and secret with a colon
  $credentials = $clientId . ":" . $secret;

  // Base64 encode the credentials
  $encodedCredentials = base64_encode($credentials);

  // Use in Authorization header
  $authHeader = "Basic " . $encodedCredentials;
  echo $authHeader;
  ?>
  ```
</CodeGroup>
