Quick Start Example

Here's a simple example to get you started.

Step 1: Get Your Bearer Token

First, you'll need to obtain a bearer token using your client_id and client_secret:

curl -X POST https://api.demo.singlefile.io/o/token/ \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "client_secret=YOUR_CLIENT_SECRET"
import requests

response = requests.post(
    "https://api.demo.singlefile.io/o/token/",
    headers={"Content-Type": "application/x-www-form-urlencoded"},
    data={
        "grant_type": "client_credentials",
        "client_id": "YOUR_CLIENT_ID",
        "client_secret": "YOUR_CLIENT_SECRET"
    }
)

token_data = response.json()
access_token = token_data["access_token"]
const formData = new URLSearchParams({
  grant_type: "client_credentials",
  client_id: "YOUR_CLIENT_ID",
  client_secret: "YOUR_CLIENT_SECRET"
});

const response = await fetch("https://api.demo.singlefile.io/o/token/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: formData
});

const { access_token: accessToken } = await response.json();
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"net/url"
	"strings"
)

func main() {
	data := url.Values{
		"grant_type":    {"client_credentials"},
		"client_id":     {"YOUR_CLIENT_ID"},
		"client_secret": {"YOUR_CLIENT_SECRET"},
	}

	resp, err := http.Post(
		"https://api.demo.singlefile.io/o/token/",
		"application/x-www-form-urlencoded",
		strings.NewReader(data.Encode()),
	)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	var result struct {
		AccessToken string `json:"access_token"`
	}
	json.NewDecoder(resp.Body).Decode(&result)
	fmt.Println("Access token:", result.AccessToken)
}
using System.Net.Http;
using System.Text.Json;

var client = new HttpClient();
var form = new FormUrlEncodedContent(new Dictionary<string, string> {
    ["grant_type"] = "client_credentials",
    ["client_id"] = "YOUR_CLIENT_ID",
    ["client_secret"] = "YOUR_CLIENT_SECRET"
});

var response = await client.PostAsync(
    "https://api.demo.singlefile.io/o/token/", form);
var json = await response.Content.ReadAsStringAsync();
var token = JsonDocument.Parse(json).RootElement
    .GetProperty("access_token").GetString()!;

The response will contain your access token:

{
  "access_token": "your_bearer_token_here",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "read write"
}

Step 2: Use the Token in API Calls

BASE_URL="https://api.demo.singlefile.io/external-api/v1"
ACCESS_TOKEN="your_bearer_token_here"

curl -X GET "${BASE_URL}/entities" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "Accept: application/json"
import requests

BASE_URL = "https://api.demo.singlefile.io/external-api/v1/"
ACCESS_TOKEN = "your_bearer_token_here"

headers = {
    "Authorization": f"Bearer {ACCESS_TOKEN}",
    "Accept": "application/json",
    "Content-Type": "application/json"
}

response = requests.get(f"{BASE_URL}entities", headers=headers)
if response.status_code == 200:
    entities = response.json()["data"]
    print(f"Found {len(entities)} entities")
else:
    print(f"Error: {response.status_code}")
    print(response.json())
const BASE_URL = "https://api.demo.singlefile.io/external-api/v1/";
const ACCESS_TOKEN = "your_bearer_token_here";

const response = await fetch(`${BASE_URL}entities`, {
  headers: {
    "Authorization": `Bearer ${ACCESS_TOKEN}`,
    "Accept": "application/json"
  }
});

if (response.ok) {
  const { data: entities } = await response.json();
  console.log(`Found ${entities.length} entities`);
} else {
  console.error(`Error: ${response.status}`);
}
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

const (
	baseURL     = "https://api.demo.singlefile.io/external-api/v1/"
	accessToken = "your_bearer_token_here"
)

func main() {
	req, _ := http.NewRequest("GET", baseURL+"entities", nil)
	req.Header.Set("Authorization", "Bearer "+accessToken)
	req.Header.Set("Accept", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	if resp.StatusCode == 200 {
		var result struct {
			Data []map[string]interface{} `json:"data"`
		}
		json.NewDecoder(resp.Body).Decode(&result)
		fmt.Printf("Found %d entities\n", len(result.Data))
	} else {
		fmt.Printf("Error: %d\n", resp.StatusCode)
	}
}
using System.Net.Http;
using System.Text.Json;

const string baseUrl = "https://api.demo.singlefile.io/external-api/v1/";
const string accessToken = "your_bearer_token_here";

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
client.DefaultRequestHeaders.Add("Accept", "application/json");

var response = await client.GetAsync($"{baseUrl}entities");
if (response.IsSuccessStatusCode)
{
    var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
    var entities = doc.RootElement.GetProperty("data").GetArrayLength();
    Console.WriteLine($"Found {entities} entities");
}
else
{
    Console.WriteLine($"Error: {response.StatusCode}");
}