Call API feature ឱ្យ survey field ធ្វើ HTTP request ទៅ external service ហើយ ប្រើ response ដើម្បី populate calculated value ឬ validate user input ។

functions ពីរ:

  • callapi() — fetch value ពី API ហើយ store ក្នុង calculatetext field
  • callapi-verify() — call API ហើយ block progress ប្រ សិ ន បើ response ខ ុ ស

callapi() — Fetch and store an API response

Syntax

  callapi(method, url, allowed_auto, max_retry, no_overwrite, extract_expr, timeout, lifetime, response_q, call_type, post_body)
  

Parameters

#Parameterការពិពណ៌នា
1methodHTTP method: 'GET''POST'
2urlAPI endpoint URL
3allowed_auto1 call ដោយ ស្វ័យប្រវត្តិ; 0 manual trigger
4max_retryMaximum retry attempts
5no_overwrite1 keep existing value
6extract_exprJSONPath expression (ឧ. $.data.name)
7timeoutRequest timeout milliseconds
8lifetimeCache duration milliseconds
9response_qField ដើម្បី store HTTP response code

Example: GET request

typenamelabelappearancecalculation
texthousehold_idHousehold ID
calculatehh_namecallapicallapi('GET', concat('https://api.example.com/households/', ${household_id}), 1, 3, 0, '$.name', 10000, 0, '')

Example: POST request

  callapi('POST', 'https://api.example.com/lookup', 1, 2, 0, '$.result.value', 15000, 0, '', '', '{"id": "##household_id##"}')
  

callapi-verify() — Validate a value against an API

Syntax

  callapi-verify(method, url, extract_expr, match_expr, timeout, constraint_mode, post_body, message)
  

Parameters

#Parameterការពិពណ៌នា
1methodHTTP method
2urlVerification API endpoint
3extract_exprJSONPath ។
4match_exprExpression comparing extracted value
5timeoutRequest timeout
6constraint_mode'soft' warning; 'hard' block

Example: Verify barcode

typenamelabelappearanceconstraint
barcodeasset_codeScan the asset barcodecallapi-verifycallapi-verify('POST', 'https://api.example.com/assets/verify', '$.valid', ". = 'true'", 10000, 'hard', '{"code": "##asset_code##"}')

Best Practices

  1. Set timeout ត្រឹម ត្រូ វ (5000–15000 ms) ។
  2. Set allowed_auto=0 សម្រាប់ verifications ។
  3. ប្រើ extract_expr ជ ា ម ួ យ specific JSONPath ។
  4. Test API calls ក្នុង offline mode ។

Limitations

  • ត ្ រ ូ វ ក ា រ network connectivity ។
  • API responses ត ្ រ ូ វ ត ែ ជ ា JSON ។
តើទំព័រនេះមានប្រយោជន៍ទេ?