GraphQL API Help

Hello,

Please forgive me if I’m missing anything obvious, but I want to create a Python GUI to accomplish a task for me, basically boiling down to changing the last digit of the account code on the fly. I am using the built-in API module in FreePBX to get data.

I think I have familiarized it with myself enough, following the tutorial to add extensions. I now want to make something that grabs, among other things, the “account code” field of an extension. I’ve tried looking around online and testing in the “GraphQL Explorer,” but can’t find if the “account code” field is even a field whose value can be returned from an API call. Am I correct in that finding?

Thanks!

If it is not there, you could query the MySQL database that houses the extension information.

I thought about that, but I’m trying to move away from the SQL queries for this application (the current version of my application uses SQL but the web page takes over a minute to load). I’m hoping an API can be faster (all I want to grab and load is the extension number, the name, and the account code).

With the original tutorial I followed I made the tutorial into a GUI and even with 2,000+ extensions in my test environment, it loads the extension number and the name within about 5 seconds, much faster than the FreePBX Extensions web page. So that’s my hope is it will be quick.

If it helps any, here is what I’m trying to do that I currently have working as just a web page within FreePBX:

In our 25 school buildings currently (thinking about our current Alcatel system we’re still on) the classroom phones have two numbers - one an internal extension, and the other a DID that can be called from the outside. We don’t want calls from the outside coming in during school hours, so a long time ago an Alcatel engineer wrote a script to automatically forward to voicemail during school hours.

With FreePBX, I’m trying to do my own script, and I’m taking advantage of the account code field, with the last digit being a flag, saying whether the extension should adhere to the schedule or whether outside calls coming in will be allowed to bypass that. Sometimes teachers want that changed, so I wanted an easy way to change on the fly.

I know I can just use the Extensions module to update the account code, but I like programming and making GUIs haha, so I wanted to make something fancy. This is the web page that takes eons to load:

Alternatively, is this field ever used for anything? I think looking through the extensions, the “SIP Alias” field isn’t being used. If I utilize that for what I want, it shouldn’t step on toes?

That field I can access with the API, so could use that.

image

Doing SQL queries directly shouldn’t be slower than the API, which is also doing queries, so it probably just needs to be optimized. You could do things like using a local script instead of running them remotely, but it’s hard to make suggestions without knowing more about what you are doing.

It seems obvious from the replies you are getting that there are not a lot of people using the API, so that should tell you something. I know that when I looked at it awhile ago I concluded that doing SQL queries had fewer potential issues and question marks.

1 Like

“If you want to support direct sip dialing of users internally or through anonymous sip calls, you can supply a friendly name that can be used in addition to the users extension to call them.”

If it is an impact or not depends on your setup. I would think the risk would be minimal. The potential impact is a station could get a call is a dial string matched an alias.

1 Like

Yeah, I may just revisit version one of what I have working. Maybe rebuild it from the ground up. I definitely love using SQL and am more familiar with it, just not the best at building efficient queries. Usually at least I start with something that works, even if it’s not the best, and then refine it until it’s nice and succinct.

I found out that field needs unique values anyway, which makes sense, but meant it wouldn’t work in my application.

I saw other fields that I could utilize, but they either could be queried with the API or updated with the API, but not both, so didn’t get that method to do anything useful either.

I’ll revisit doing it with SQL, refine what I have.

1 Like

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