Is it possible to use the $count function to count members?
Is it possible to use the $count directive with $filter to count number of members (rather than contacts)? Here's my google apps script call below. I get this error:
Request failed for https://api.wildapricot.org/v2/accounts/210450/contacts?$count&$filter='Member%20eq%20true' returned code 400. Truncated server response: {"code":"Search","message":"Failed to build expression tree. Multiple expression roots: Argument:Member eq true"} (use muteHttpExceptions option to examine full response)
I think I may have to iterate through a get all contacts call instead and count them manually, but I am not sure how to do that.
function getMemberCount()
{
Logger.clear();
var urls = urlBuilder();
var ui = SpreadsheetApp.getUi();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var token = getToken(ui, urls.getAuthServiceUrl());
var accountId = getDataFromApi(urls.getAccountsListUrl(), token)[0].Id;
var contactFields = getDataFromApi(urls.getContactFieldsUrl(accountId), token);
// Example call: '?$async=false&simpleQuery=John'
// '$async' => 'false', // execute request synchronously
// '$top' => 10, // limit result set to 10 records
// '$filter' => 'Member eq true', // filter only members
// '$select' => 'First name, Last name'
// Count members
// GET {baseAPIaddress}/v2/Accounts/{accountID}/Contacts?$count
var url = urls.getContactsListUrl(accountId) + '?$count&$filter=\'Member eq true\'';
var result = getDataFromApi( url, token, "GET");
ui.alert('Number of Contacts: ' + result.Count);
}
Happy to contribute my resulting new code for use in the API documentation (will submit to GitHub once I get more of it working).
There was no activity for 5 months. We archive this thread.
Alex, if you’d like to share your code, feel free to reopen this idea or make a new one.
-
Hi Alex,
You are right, the reason was in quotes.
Great to hear you want to contribute. As you are ready, please, let me know and I will add a link to your code into API documentation.
Dmitry
-
Alex Sirota commented
Just realized you don't have to escape the single quotes because you don't need them at all! Count working now with this string
var url = urls.getContactsListUrl(accountId) + '?$count&$filter=Member eq true';