Clients

Für die REST API stellen wir fertige API-Clients in PHP und Go bereit. Aktualisierungen der Clients werden zeitgleich mit neuen Versionen der REST API veröffentlicht.

PHP Client

Mit dem offiziellen PHP-Client kann die REST API von Customa von PHP aus angesprochen werden. Der Client ist als Library tid/customa auf Packagist verfügbar.

Es folgt ein Beispiel für die Nutzung des Clients:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
$config = new Configuration();
$authApi = new AuthApi(config: $config);
$customerApi = new CustomerApi(config: $config);

$authResponse = $authApi->authLogin(new AuthLoginRequest([
    "username" => $username,
    "password" => $password,
    "project" => $project,
]));

$config->setAccessToken($authResponse->getToken());

$searchResponse = $customerApi->customerSearch(new SearchRequest([
    "page" => 1,
    "page_size" => 1,
    "filter" => []
]));

$authApi->authLogout();

echo "{$searchResponse->getTotalCount()} Customers found.\n";

Go Client

Der Go-Client stellt die Customa API über das Modul github.com/trust-in-dialog-Services-GmbH/customa-go/v3 für Go-Projekte bereit.

Beispiel für Nutzung des Clients:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main

import (
	"context"
	"fmt"
	"log/slog"
	"os"

	"github.com/trust-in-dialog-Services-GmbH/customa-go/v3"
)

func main() {
	slog.SetLogLoggerLevel(slog.LevelDebug)

	// Kontext, Konfiguration und Client erstellen
	ctx := context.Background()
	config := customa.NewConfiguration()
	client := customa.NewAPIClient(config)

	// Authentifizierung mit Nutzername, Passwort und Projekt
	loginRequest := customa.NewAuthLoginRequest(
		os.Getenv("CUSTOMA_USER"),
		os.Getenv("CUSTOMA_PASSWORD"),
		10,
	)
	loginResponse, _, err := client.AuthAPI.AuthLogin(ctx).AuthLoginRequest(*loginRequest).Execute()
	if err != nil {
		slog.ErrorContext(ctx, "Login failed", "error", err)
		os.Exit(1)
	}
	slog.DebugContext(ctx, "Login succeeded")
	ctx = context.WithValue(ctx, customa.ContextAccessToken, loginResponse.Token)

	// Kunden zählen
	searchRequest := customa.NewSearchRequest(1, 1, []customa.SearchFilter{})
	customerResponse, _, err := client.CustomerAPI.CustomerSearch(ctx).SearchRequest(*searchRequest).Execute()
	if err != nil {
		slog.ErrorContext(ctx, "Searching for customers failed", "error", err)
		os.Exit(1)
	}
	slog.InfoContext(ctx, fmt.Sprintf("%d Customers found", customerResponse.TotalCount))

	// Abmelden und Token löschen
	_, err = client.AuthAPI.AuthLogout(ctx).Execute()
	if err != nil {
		slog.ErrorContext(ctx, "Logout failed", "error", err)
		os.Exit(1)
	}
	slog.DebugContext(ctx, "Logout succeeded")
}