Does anyone know of a “getting started” or “hello world” like write up on the PBX API module? Concretely, I’d love to be able to allow a process on another machine to periodically query for all extensions that belong to a particular Group (setup under Admin > User Management > Groups).
There may be one out there, but I haven’t found it.
I see the Connectivity > API page, but I don’t understand what needs to be done to make API calls to our FreePBX instance, or even how to verify it’s available.
Has anyone been down this path already? Does anyone know of a “Hello World” example for the FreePBX API??
@comtech, I’ve read all those links and pages, but they don’t show how to use the FreePBX API. There is nothing that shows even a basic connection to FreePBX.
The REST stuff is pretty limited but a ton of folks use graphql which is generally self documenting and can be seen through the gui. Most of the rest things are simply documented in the code. Sometimes the best move is to not use the api and make something else.
Specifically for what you want to do… Userman doesn’t have support for graphql but I am sure someone could write it. It also doesn’t support anything with groups. You can essentially pull a list of users.
@jfinstrom, I am not interested in the REST API since that seems to be deprecated. But, the graphql doesn’t seem to be responding the way I would expect. When I go to Connectivity > API > GraphQL Explorer, set the scope to gql, and Reload Explorer, I get this:
Which says that I “Cannot query field "version" on type "Query".”, which isn’t terribly helpful. There is no information on what went wrong. I’m assuming “version” is a pretty minimalist query on the FreePBX graphql server.
Interestingly, if I Reload Explorer after receiving that minimalist error message, I get an unhandled exception dump with this info:
at exports.assertValidName (https://pbx.survivalflightinc.com/admin/assets/api/js/graphiql.min.js?load_version=15.0.11:1:704315)
at https://pbx.survivalflightinc.com/admin/assets/api/js/graphiql.min.js?load_version=15.0.11:1:658739
at Array.map (<anonymous>)
at https://pbx.survivalflightinc.com/admin/assets/api/js/graphiql.min.js?load_version=15.0.11:1:658679
at new GraphQLEnumType (https://pbx.survivalflightinc.com/admin/assets/api/js/graphiql.min.js?load_version=15.0.11:1:659467)
at https://pbx.survivalflightinc.com/admin/assets/api/js/graphiql.min.js?load_version=15.0.11:1:720948
at getNamedType (https://pbx.survivalflightinc.com/admin/assets/api/js/graphiql.min.js?load_version=15.0.11:1:721919)
at https://pbx.survivalflightinc.com/admin/assets/api/js/graphiql.min.js?load_version=15.0.11:1:723732
at Array.map (<anonymous>)
at exports.buildClientSchema (https://pbx.survivalflightinc.com/admin/assets/api/js/graphiql.min.js?load_version=15.0.11:1:723693)
Nothing jumps out at me as useful for getting the broken query to work, but it looks like fail2ban might have a crunchy assert() somewhere in it’s codebase. The assert() is definitely not liking the hyphen in the WHICH_fail2ban-client name.
Since it sounds like you’re able to query your server using the graphql PBX API, do you have a minimal code example that successfully queries your server you can share? For example, just querying for the version maybe? I’m planning on coding my client in C#/.Net, but your example can be in any language. That would be very helpful for me if you can.
The commercial module rest API is deprecated. The API module does both rest and graphql. That aside you missed the second half where the code for what you want doesn’t exist so you or someone needs to write it.