Files
Snippets/bruno-idoit-session.md
T
Sven Riwoldt 8ddd29a1fc Bruno Cookies
2026-07-20 08:30:10 +02:00

102 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Bruno: Session zur i-doit aufbauen
In Bruno bekommst du eine "Session" über eine Kombination aus **Environment-Variablen** und dem **API-Key-Login von i-doit**. i-doit selbst nutzt keine klassischen Cookie-Sessions für die JSON-RPC-API, sondern authentifiziert jeden Request per Header der "Session-Charakter" kommt also über gespeicherte Variablen, die alle Requests teilen.
## 1. Environment anlegen
Anlegen eines Environment `demo-idoit` mit:
```
base_url: https://demo.i-doit.com/src/jsonrpc.php
apikey: c1ia5q
username: admin
password: admin
```
![](idoit01.png)
![](idoit02.png)
## 2. Login-Request (holt die Session-ID)
i-doit unterstützt eine echte Session über `idoit.login`. Der Response liefert einen `X-RPC-Auth-Session`-Header, den du für Folge-Requests wiederverwendest.
**POST** `{{base_url}}`
Headers:
```
Content-Type: application/json
X-RPC-Auth-Username: {{username}}
X-RPC-Auth-Password: {{password}}
```
![](idoit03.png)
Body (JSON):
```json
{
"version": "2.0",
"method": "idoit.login",
"params": { "apikey": "{{apikey}}" },
"id": 1
}
```
Im **Script → Post Response** die Session-ID in eine Variable schreiben:
```javascript
bru.setEnvVar("session_id", res.getHeader("x-rpc-auth-session"));
```
## 3. Folge-Requests mit der Session
Alle weiteren Requests nutzen dann statt Username/Passwort nur noch:
```
Content-Type: application/json
X-RPC-Auth-Session: {{session_id}}
```
Body z. B. für eine Objektabfrage:
```json
{
"version": "2.0",
"method": "cmdb.objects.read",
"params": { "apikey": "{{apikey}}", "filter": { "type": 5 } },
"id": 1
}
```
## 4. Logout (optional)
```json
{ "version": "2.0", "method": "idoit.logout", "params": { "apikey": "{{apikey}}" }, "id": 1 }
```
mit Header `X-RPC-Auth-Session: {{session_id}}`.
---
**Kernpunkt:** Die Session-ID aus dem Login-Response wird per Post-Response-Script als Environment-Variable gespeichert und von allen Requests im selben Environment geteilt. Damit sparst du dir den Login-Roundtrip pro Abfrage und hast quasi eine durchgehende Session.
#############
# Stolperstein
Während der Arbeiten an Bruno ( zu Hause ) bin ich über folgendes Problem gestolpert.
Nach dem holen der Session-ID kam immer ein 500er-Fehler. Das lag daran das ich
1. die ID geholt habe
2. Bruno wohl die Cookies speichert
Die Cookies kann man in Bruno über die folgenden Punkte ausschalten:
1. ![](Bruno_Cookies_1.png)
2. ![](Bruno_Cookies_2.png)