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