Optisway ana sayfa
Dokümantasyon menüsü

REST API referansı: Anahtarlar

GET /me, bir anahtarın hangi organizasyona ve projeye eriştiğini, erişim düzeyini ve süresinin ne zaman dolduğunu gösterir. Yeni bir anahtarın çalıştığını doğrulamak için önce bunu çağırın.

Anahtarımı doğrula GET /me

Gönderdiğiniz API anahtarını açıklar: adı, erişim düzeyi, oluşturulma ve sona erme zamanı, kuruluşu ve sınırlı olduğu proje. Geçerli her anahtar bu uç noktayı çağırabilir; yeni bir anahtarı CI'a eklemeden önce denemenin en hızlı yolu budur. Örnekteki anahtarın run erişimi vardır ve tüm projeleri kapsar, bu yüzden project değeri null olur.

Gereken anahtar erişimi: Okuma

Parametreler

Bu uç nokta parametre almaz.

Örnek istek

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")}");

Örnek yanıt

Döndürür: key, organisation ve project alanlarını içeren bir nesne (tüm projeleri kapsayan anahtarda project null olur).

Durum: 200 OK

Başlıklar: Content-Type: application/json; charset=utf-8 Cache-Control: no-store

Yanıt gövdesi: Anahtarımı doğrulaJSON
{
  "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
}

Alabileceğiniz hatalar

  • unauthorized 401 Anahtar eksik, hatalı biçimli, bilinmiyor, iptal edilmiş veya süresi dolmuş ya da onu oluşturan kişi artık üye değil.
  • rate_limited 429 Anahtar çok fazla istek gönderdi; Retry-After içindeki saniye kadar bekleyin.
  • unavailable 503 Bizim tarafımızda geçici bir sorun var; daha sonra tekrar deneyin.