ACF Library

ContaVerifyAPIresponce

Back to List

Description: Look for error message in Conta API responce

FileMaker Prototype:

Set Variable [$res; ACF_Run("ContaVerifyAPIresponce"; JSON_responce)]

Category: CONTA API

Function source:

Function ContaVerifyAPIresponce (json responce)
   array string messages; 
   string msg, keys = list_keys(responce); 
   int er = pos (keys, "errors" ); 
   int me = pos (keys, "messages" ); 
   int i,j;
   if (me<0 && er<0) then
      return true;
   end if
   case
      : (me>=0)
         msg = responce["messages.EN"]; 
         messages[] = msg;
      : (er>=0)
         j = sizeof (responce["errors"]); 
         for (i = 1, j)
            msg = responce[format("errors[%d].messages.EN", i)]; 
            messages[] = string(i)+": "+msg;
         end for
   end case
   throw "Errors: \n" + implode ("\n", messages); 
   // return true; 
end

The ContaVerifyAPIresponce Function is used by the other CONTA API functions to look for any error message in the API responce from CONTA. If it is an error there, it throws an exception, otherwise it returns true;

Example

res = HTTP_POST ( url, data, hdr ); 
JSON ApiRes = res; 
if (ContaVerifyAPIresponce(ApiRes)) then
    // Do updates using the ApiRes
end if

Example for API responce with errors in it:

ERROR - Exception: Thrown in: contaverifyapiresponce:Errors: 
1: bookkeepingAccountNo is prohibited for this activity
2: sumNet is prohibited for this activity
3: sumTotal is prohibited for this activity
(pc:760)
Back to List