Preferred way of creating a public route for a module

I am creating a module and I want to expose an endpoint that is publicly accessible. I can’t see a way how to do this. Can someone point me in the right direction?

This is way to vague for anyone to do anything with. Without knowing any details and the end game we can’t provide a preferred way.

Expose it how? When you say publicly accessible do you mean over the Internet or just in a public space where anyone can access it? Are you referring to SIP routes, a network route?

My bad I should have been more descriptive. What I want to do is to be able to make an HTTP request to an endpoint my module creates. The endpoint would return JSON. I haven’t been able to find documentation on how to do this. I know how to make module pages that are visible within the FreePBX administration GUI but not something public.

You keep saying “endpoint”. You have to realize that an endpoint is more than a phone, a PBX can be an endpoint. A server can be an endpoint. The list continues.

Are you talking about using a phone’s HTTP API functionality to seen information/events to the phone and get a response?

The endpoint I am talking about is for my webserver to send a request to an endpoint and process the JSON returned from it. All I am trying to do is hit a PHP file that returns JSON (endpoint). The PHP file will make database queries and pull data from AMI and return it. I will not be using this endpoint with anything other than a webserver. So for example making a GET request to “http://myFreePBXURL.com/myEndpoint” or “http://myFreePBXURL.com/myEndpoint.php

So this is sounding like you want to run some sort of API, RESTful or not, on the PBX and then remotely communicate with it to get details? Correct? You’re wanting help on how to create this API to begin with?

Yes that is wheat I am trying to accomplish. I just didn’t know if there was a prefered FreePBX way of doing it using their module system or if I am going to have to roll my own? I can’t find documentation on accomplishing what I want in the FreePBX forums or documentation. I’ve looked for similar modules but can’t find any.

The API heavy lifting has been incorporated in FreePBX 15, I recommend you start with that and note the API resources linked in this recent announcement:

Unfortunately we are on version 14 right now and probably won’t be upgrading for a while. Was there a prefered way or some tutorial you know of to do something similar, albeit more work?

Again, you are not providing details that would help us help you. An API is an API. You can either using the existing API that will have certain triggers can that be called on and return a specific set of data on something. Is that going to be enough for you? Is what the current API support has enough? Does it do all you want? Probably not.

So right now since it seems this is a remote system hitting the PBX boxes to get information so there is nothing that requires this is actually be done in a FreePBX module. You can just create the API and install it on the server. That’s what I’ve done in the past.

Have you written an API before?

I figured it out by looking at the restapi module https://github.com/FreePBX-ContributedModules/restapi

@lgaetz was able to figure out what I wanted from my description so I am not sure how else I can explain it.

I have written API’s before. I was simply asking if there was a FreePBX way of creating public endpoints from a custom module because I wanted to avoid doing what you mentioned in your previous comment of installing things manually on the server. Based on the way the restapi FreePBX module works it just creates a folder and a symlink to the module folder to expose public endpoints. That is exactly what I wanted to accomplish.

Thanks for helping though

It’s a contributed module. It doesn’t exist in repos to install from, so guess what? You’re manually installing it on the server. Can’t get around that.

Also have you actually looked at that module? It hasn’t had any real updates in over 3 years, more importantly the API endpoint code for the modules hasn’t been touched in over 3 years. That should be something to seriously consider, that means this module hasn’t been updated for anything in FreePBX 14 and any changes in the modules that have happened in 3 years.

I never had to install that module it came installed by default on several installations of FreePBX 14, so no I don’t have to install anything manually. Also it works perfectly fine with version 14. Just because something hasn’t been touched in three years doesn’t necessarily mean it is insecure or shouldn’t be used. I have read through most of the source code and it seems like a very nice module and I have only had to make one change to make my life easier, other than that it is solid.

2 Likes

There is a REST API in FreePBX 14, but it is NOT the GitHub module. It is there to support (among other things) the UCP and Sangoma’s phone module (whose name escapes at this moment). The GitHub module may have been the genesis for the embedded REST API, but it is not the same thing.

The REST API (restapi) module has been around for a while. It once was a dependency for the Phone Apps (restapps) module, but not since ver. 12, and as a result has been hardly touched since.

1 Like

The REST API in FreePBX 14 is the GitHub module (restapi). Just look at the changelog it matches what is in the repo.


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