getContaOrganizationID
Back to ListDescription: Get the organizetion ID @ conta to apply in other API calls.
FileMaker Prototype:
Set Variable [$res; ACF_Run("getContaOrganizationID"; string_APIkey; bool_production; string_orgName)]
Category: CONTA API
Dependencies
- getContaBaseURL: Get the CONTA API base URL, Sandbox or production URLs
Function source:
function getContaOrganizationID ( string APIkey, bool production, string orgName )
$$ContaApiKey = APIkey;
string hdr = 'apiKey:'+APIkey;
string url = getContaBaseURL(production)+"/invoice/organizations";
string result, compName;
string gCompID, s,name ;
// Do the API call
result = HTTP_GET(url, hdr);
// Handle the result, a JSON object
// print result;
JSON res;
// Our JSON implementation likes better to have the array in a tag
// might be improved in a later plugin release.
res = '{"a":'+result+'}';
// loop the result to find matching name
int i, j= sizeof ( res["a"]);
for (i=1, j)
s = format ("a[%d].", i); // a[1].
name = res[s+"name"]; // a[1].name
if ( upper(orgName) == upper(name)) then
gCompID = res[s+"id"];
$$ContaCompID = gCompID;
$$ContaCompName = res[s+"name"];
break; // We found it, break out of the loop
end if
end for
return gCompID;
end
The getContaOrganizationID function retrieves the organization ID for a specified company name from CONTA. This function calls the API to get a list of all organizations accessible via the provided API key, then loops through the list to find the one matching your organization's name.
This function is useful in a configuration setup within your FileMaker application to store the company ID in the app's preferences. Having this ID is essential, as most other API calls to CONTA require the organization number as a parameter.
Example
Set Field [Preferences::ContaID; ACF_Run("getContaOrganizationID"; Preferences::ContaSandboxApiKey; false; "MyCompany LTD")]
This example retrieves and stores the company ID from CONTA in the ContaID field, making it available for future API calls.
Saving this ID in your application preferences is recommended to avoid repeatedly requesting it with each API call to CONTA.
Note: If the function returns nothing, it may be due to an exact name match issue. In that case, you can uncomment the print statements to view the JSON response in the console, which can help identify any discrepancies, such as a misspelled name.
