Code-Beispiele

curl-, JavaScript- und Python-Snippets

6 Min. Lesezeit
Diesen Abschnitt drucken

Zum Kopieren: Beispiele für die häufigsten API-Aufrufe. Legen Sie Ihren API-Schlüssel in FMK ab (er beginnt mit fmk_). Lassen Sie den Code genau so stehen: Feldnamen, Header-Namen und Enum-Werte gehören zum Protokoll und werden nie übersetzt.

curl

  • Schlüssel prüfen: curl -H "Authorization: Bearer $FMK" https://freemaint.com/api/v1/public-api/whoami
  • Arbeitsaufträge auflisten: curl -X POST -H "Authorization: Bearer $FMK" -H "Content-Type: application/json" -d '{"query":"{ workOrders(limit:5){ id title status } }"}' https://freemaint.com/api/v1/graphql
  • Eine Lagereinheit verbrauchen: curl -X POST -H "Authorization: Bearer $FMK" -H "Content-Type: application/json" -d '{"query":"mutation { adjustStock(id:812, quantity:-1, reason:\"ERP sync\"){ id quantity } }"}' https://freemaint.com/api/v1/graphql

JavaScript (fetch)

Mit fetch, unter Node.js oder im Browser: const r = await fetch('https://freemaint.com/api/v1/graphql', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.FMK}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ query: '{ workOrders(limit:5){ id title } }' }) }); const data = await r.json();

Python (requests)

Mit der Bibliothek requests: import requests; r = requests.post('https://freemaint.com/api/v1/graphql', headers={'Authorization': f'Bearer {FMK}'}, json={'query': '{ workOrders(limit:5){ id title } }'}); print(r.json())

Python: Barcode-Kiosk

Code scannen, Ersatzteil nachschlagen, dann eine Einheit abziehen: import requests; H={'Authorization': f'Bearer {FMK}'}; U='https://freemaint.com/api/v1/graphql'; code=input('Scan: '); part=requests.post(U,headers=H,json={'query':'query($c:String!){ part(barcode:$c){ id name description quantity minQuantity maxStockLevel unitOfMeasure imageUrl area location{name} vendor{name website} } }','variables':{'c':code}}).json()['data']['part']; requests.post(U,headers=H,json={'query':'mutation($id:Int!){ adjustStock(id:$id,quantity:-1,reason:"Kiosk"){ id quantity } }','variables':{'id':int(part['id'])}})

Tipp

Überprüfen Sie in der Antwort immer „X-RateLimit-Remaining“ – Ihre Integration sollte Sie warnen, bevor die Tagesobergrenze ausgeschöpft wird.

War diese Seite hilfreich?