Issue
-
How do I filter accounts by custom field with Rest APi?
I'm on 2024.q3.9, fp3, and I have added a custom field to account (From Control Panel --> Custom Fields --> Account Entry)
Name: Foo
Key: foo
Data type: text
Localized field name
Searchable: as keyword
Yet when I try to filter it, I get a bad request:$curl -X 'GET' -H 'accept: application/json' --user "$CREDS_PLAIN" \
"http://localhost:8080/o/headless-admin-user/v1.0/accounts?filter=foo%20eq%20'bar'"
{
"status" : "BAD_REQUEST",
"title" : "A property used in the filter criteria is not supported: foo eq 'bar'",
"type" : "InvalidFilterException"
}
Environment
- QR
Resolution
-
the headless API works only for custom fields added as Object fields (the new Objects framework)
But you used the older expando framework for adding the custom field.
For that, you can rather use the JSONWS API, for which you can find a testing UI at /api/jsonws page.
There, for example, you can see that you can call the get-account-entries endpoint (after choosing the context name "account"). Please see in attached get-account-entries.png an example of how to invoke it. The result looks something like this (I created 2 accounts previously):
[
{
"accountEntryId": "33114",
"companyId": "92662428485709",
"createDate": 1734008128749,
"defaultBillingAddressId": "0",
"defaultCPaymentMethodKey": "",
"defaultShippingAddressId": "0",
"description": "",
"domains": "",
"emailAddress": "",
"externalReferenceCode": "cfb770c1-a5e0-8333-6181-57d485404709",
"logoId": "0",
"modifiedDate": 1734008129128,
"mvccVersion": "3",
"name": "acc1",
"parentAccountEntryId": "0",
"restrictMembership": true,
"status": 0,
"statusByUserId": "20123",
"statusByUserName": "Test Test",
"statusDate": 1734008129114,
"taxExemptionCode": "",
"taxIdNumber": "",
"type": "business",
"userId": "20123",
"userName": "Test Test",
"uuid": "cfb770c1-a5e0-8333-6181-57d485404709"
},
{
"accountEntryId": "33119",
"companyId": "92662428485709",
"createDate": 1734008146391,
"defaultBillingAddressId": "0",
"defaultCPaymentMethodKey": "",
"defaultShippingAddressId": "0",
"description": "",
"domains": "",
"emailAddress": "",
"externalReferenceCode": "2866a252-a26b-e37e-68d7-7886266b94ac",
"logoId": "0",
"modifiedDate": 1734008146459,
"mvccVersion": "3",
"name": "acc2",
"parentAccountEntryId": "0",
"restrictMembership": true,
"status": 0,
"statusByUserId": "20123",
"statusByUserName": "Test Test",
"statusDate": 1734008146449,
"taxExemptionCode": "",
"taxIdNumber": "",
"type": "business",
"userId": "20123",
"userName": "Test Test",
"uuid": "2866a252-a26b-e37e-68d7-7886266b94ac"
}
]
As you can see, this doesn't include yet the values for the custom field. To further obtain those, you can use a further JSONWS endpoint get-data (context: portal, section: EXPANDOVALUE). And you need to call this for every element (every account) returned in the result above. Please see attached Screenshot 2024-12-12 142350.png for an example. You fill in the classPK field with the accountEntryId you got in the result above.
Alternatively, you might consider not using the old expando kind of custom fields, but rather adding the new field to the Account object (From Control Panel --> Objects -->Account). The headless API you wanted to try originally should be able to work with such a field. Note that in this case you don't see the new field on the UI when creating a new account from Control Panel --> Accounts, so you cannot provide it from the UI. Hence, you need to do the account creation also programmatically, with a headless API.