よく使う API 操作のコピペ用サンプルです。API キーを FMK に入れてください(fmk_ で始まります)。コードはそのまま使ってください: フィールド名、ヘッダー名、列挙値はプロトコルの一部であり、翻訳してはいけません。
curl
- キーを確認する: curl -H "Authorization: Bearer $FMK" https://freemaint.com/api/v1/public-api/whoami
- 作業指示を一覧表示する: 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
- 在庫を 1 単位消費する: 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)
Node.js またはブラウザーで fetch を使う: 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)
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:バーコードキオスク
コードをスキャンし、部品を検索して 1 単位減らす: 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'])}})
ヒント
関連記事
このページは役に立ちましたか?