Optisway Startseite
Dokumentationsmenü

REST-API-Referenz: Schlüssel

GET /me zeigt, welche Organisation und welches Projekt ein Schlüssel erreicht, seine Zugriffsstufe und wann er abläuft. Rufen Sie es zuerst auf, um zu prüfen, ob ein neuer Schlüssel funktioniert.

Eigenen Schlüssel prüfen GET /me

Beschreibt den gesendeten API-Schlüssel: Name, Zugriffsstufe, Erstell- und Ablaufzeit, Organisation und das Projekt, auf das er beschränkt ist. Jeder gültige Schlüssel darf ihn aufrufen – so prüfen Sie einen neuen Schlüssel am schnellsten, bevor Sie ihn in der CI eintragen. Der Beispielschlüssel hat run-Zugriff und gilt für alle Projekte, daher ist project null.

Benötigt einen Schlüssel mit Zugriff: Lesen

Parameter

Dieser Endpunkt hat keine Parameter.

Beispielanfrage

curl --fail-with-body -sS "https://optisway.com/api/v1/me" \
  -H "Authorization: Bearer $OPTISWAY_API_KEY"
// Node.js 18+: save as optisway.mjs and run `node optisway.mjs`
const url = "https://optisway.com/api/v1/me";
const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.OPTISWAY_API_KEY}`,
  },
});
if (!response.ok) {
  const { error, message } = await response.json();
  console.error(`${response.status} ${error}: ${message}`);
  process.exit(1);
}
const body = await response.json();
console.log(`Organisation: ${body.organisation.name}`);
console.log(`Key access: ${body.key.access}`);
# pip install requests
import os
import sys

import requests

api_key = os.environ["OPTISWAY_API_KEY"]
response = requests.get(
    "https://optisway.com/api/v1/me",
    headers={"Authorization": f"Bearer {api_key}"},
    timeout=30,
)
if not response.ok:
    envelope = response.json()
    print(f"{response.status_code} {envelope['error']}: {envelope['message']}", file=sys.stderr)
    sys.exit(1)
body = response.json()
print("Organisation:", body["organisation"]["name"])
print("Key access:", body["key"]["access"])
require "json"
require "net/http"
require "uri"

uri = URI("https://optisway.com/api/v1/me")
request = Net::HTTP::Get.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch("OPTISWAY_API_KEY")}"
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
unless response.is_a?(Net::HTTPSuccess)
  envelope = JSON.parse(response.body)
  warn "#{response.code} #{envelope["error"]}: #{envelope["message"]}"
  exit 1
end
body = JSON.parse(response.body)
puts "Organisation: #{body["organisation"]["name"]}"
puts "Key access: #{body["key"]["access"]}"
<?php
$curl = curl_init("https://optisway.com/api/v1/me");
curl_setopt_array($curl, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("OPTISWAY_API_KEY"),
  ],
]);
$body = curl_exec($curl);
if ($body === false) {
  fwrite(STDERR, curl_error($curl) . "\n");
  exit(1);
}
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
if ($status < 200 || $status >= 300) {
  $envelope = json_decode($body, true);
  fwrite(STDERR, "$status {$envelope['error']}: {$envelope['message']}\n");
  exit(1);
}
$data = json_decode($body, true);
echo "Organisation: {$data['organisation']['name']}\n";
echo "Key access: {$data['key']['access']}\n";
// Java 11+: save as Main.java and run `java Main.java`
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  public static void main(String[] args) throws Exception {
    String url = "https://optisway.com/api/v1/me";
    HttpRequest request = HttpRequest.newBuilder(URI.create(url))
        .header("Authorization", "Bearer " + System.getenv("OPTISWAY_API_KEY"))
        .build();
    HttpResponse<String> response = HttpClient.newHttpClient()
        .send(request, HttpResponse.BodyHandlers.ofString());
    if (response.statusCode() >= 300) {
      String error = response.body();
      System.err.println(response.statusCode() + " " + field(error, "error") + ": "
          + field(error, "message"));
      System.exit(1);
    }
    String body = response.body();
    System.out.println("Organisation: " + field(body.substring(body.indexOf("\"organisation\"")), "name"));
    System.out.println("Key access: " + field(body.substring(body.indexOf("\"key\"")), "access"));
  }

  /** The first string value of a JSON key (dependency-free; Jackson or Gson parse JSON properly). */
  static String field(String json, String key) {
    Matcher match = Pattern.compile("\"" + key + "\"\\s*:\\s*(?:\"((?:[^\"\\\\]|\\\\.)*)\"|null)")
        .matcher(json);
    return match.find() ? match.group(1) : null;
  }
}
package main

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

func main() {
	url := "https://optisway.com/api/v1/me"
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("OPTISWAY_API_KEY"))
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	if resp.StatusCode >= 300 {
		var envelope struct {
			Error   string `json:"error"`
			Message string `json:"message"`
		}
		_ = json.NewDecoder(resp.Body).Decode(&envelope)
		fmt.Fprintf(os.Stderr, "%d %s: %s\n", resp.StatusCode, envelope.Error, envelope.Message)
		os.Exit(1)
	}
	var body map[string]any
	if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
		panic(err)
	}
	fmt.Println("Organisation:", body["organisation"].(map[string]any)["name"])
	fmt.Println("Key access:", body["key"].(map[string]any)["access"])
}
// .NET 8: `dotnet new console`, replace Program.cs with this file, then `dotnet run`
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
  new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("OPTISWAY_API_KEY"));
var url = "https://optisway.com/api/v1/me";
using var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
  var envelope = await response.Content.ReadFromJsonAsync<JsonElement>();
  var error = envelope.GetProperty("error");
  var message = envelope.GetProperty("message");
  Console.Error.WriteLine($"{(int)response.StatusCode} {error}: {message}");
  Environment.Exit(1);
}
var body = await response.Content.ReadFromJsonAsync<JsonElement>();
Console.WriteLine($"Organisation: {body.GetProperty("organisation").GetProperty("name")}");
Console.WriteLine($"Key access: {body.GetProperty("key").GetProperty("access")}");

Beispielantwort

Liefert: Ein Objekt mit key, organisation und project (null bei einem Schlüssel für alle Projekte).

Status: 200 OK

Header: Content-Type: application/json; charset=utf-8 Cache-Control: no-store

Antwort-Body: Eigenen Schlüssel prüfenJSON
{
  "key": {
    "id": "17",
    "name": "GitHub Actions",
    "keyId": "7hx2k9mq",
    "access": "run",
    "createdAt": "2026-10-19T08:00:00.000Z",
    "expiresAt": null
  },
  "organisation": {
    "id": "7",
    "name": "Acme"
  },
  "project": null
}

Mögliche Fehler

  • unauthorized 401 Der Schlüssel fehlt, ist fehlerhaft, unbekannt, widerrufen oder abgelaufen, oder sein Ersteller ist kein Mitglied mehr.
  • rate_limited 429 Der Schlüssel hat zu viele Anfragen gesendet; warten Sie die Sekunden aus Retry-After ab.
  • unavailable 503 Ein vorübergehendes Problem bei uns; versuchen Sie es später erneut.