Getting Started for FreePBX API (PBX API Module)

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 was hoping there might be a getting started tutorial under the Sangoma Documentation URI, but it looks like that link is out of date. It redirects to https://sangomakb.atlassian.net/wiki/spaces/PG/overview which appears to just be an overview of the generic GUI, not the PBX API.

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??

PBX GUI : API GraphQL (sangoma.com)

PBX GUI : API GraphQL Documentation (sangoma.com)

PBX GUI : API GraphQL Explorer (sangoma.com)

PBX GUI : GraphQL PBX APIs Documentation (sangoma.com)

PBX GUI : API Scope Visualizer (sangoma.com)

Is anyone using the PBX 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.

Bump…

Anyone out there using the PBX API module?

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. :cowboy_hat_face:

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.

We use the GraphQL API extensively. The “version” query doesn’t work on any PBX I’ve seen, so it’s a little misleading.

Replace the version query with the following:

{
  fetchAllExtensions {
    extension {
      extensionId,
      tech
    }
  }
}

Click the run button and the output will appear on the right hand side. The output should look something like this:

{
  "data": {
    "fetchAllExtensions": {
      "extension": [
        {
          "extensionId": "101",
          "tech": "pjsip"
        }
      ]
    }
  }
}

Use the GraphQL Documentation tab to look up the fetchAllExtensions query and hopefully this example will set you on the right path.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.