အသုံးအများဆုံး API လုပ်ဆောင်ချက်များအတွက် ကူးထည့်ရန် နမူနာများ။ သင့် API key ကို FMK ထဲထည့်ပါ (fmk_ ဖြင့်စသည်)။ ကုဒ်ကို အတိအကျ ထားပါ- field အမည်၊ header အမည်နှင့် enum တန်ဖိုးများသည် protocol ၏ အစိတ်အပိုင်းဖြစ်ပြီး ဘယ်တော့မှ ဘာသာမပြန်ပါ။
curl
- Key ကို စစ်ဆေးရန်- curl -H "Authorization: Bearer $FMK" https://freemaint.com/api/v1/public-api/whoami
- Work order များ စာရင်းပြရန်- 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
- စတော့မှ တစ်ယူနစ် သုံးစွဲရန်- 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 သို့မဟုတ် browser တွင် 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 library ဖြင့်- 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: ဘားကုဒ် ကီးအော့စ်
ကုဒ်ကို စကင်ဖတ်ပြီး part ကိုရှာကာ တစ်ယူနစ် နုတ်ပါ- 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'])}})
အကြံပြုချက်
ဆက်စပ် ဆောင်းပါးများ
ဤစာမျက်နှာသည် အသုံးဝင်ပါသလား။