How to add secret in extension at the time creation via GraphQL

freepbx
Tags: #<Tag:0x00007f4f4514c5a8>

(Amardeep Kashyap) #1

HI,
when i am going to create an extension via GraphQL API, I dont have any option to set secret on extension
now I am confused without secret or password how to use this created extension

given example
1. Api to add Extension
GQLAPI: /admin/api/api/gql

parameters:
mutation {
addExtension(
input: {
extensionId: 9090090115
name: "api test"
tech: "pjsip"
channelName: "APi Test2"
outboundCid: "12345678901"
email: "xyzabc@gmailcom"
umGroups: "1"
umEnable: true
vmPassword: "asda"
vmEnable: true
callerID: "234234324"
emergencyCid: "1221333331"
clientMutationId: "test1231"
}
) {
status
message
}
}

here in which keyword i can define the password/secret for this extension.


(Itzik) #2

See documentation: https://wiki.freepbx.org/display/FPG/Core+Module+GraphQL+APIs#CoreModuleGraphQLAPIs-CreateExtension

See also

https://wiki.freepbx.org/display/FDT/FreePBX+GraphQL+Provisioning+Tutorial


#3

I don’t see any way of specifying the SIP password in that documentation. Also, is there any timeline/roadmap for adding the ability to set other parameters not listed in the documentation for SIP devices (like the accountcode especially in my case!)…

In addition, does not seem like any support yet for Inbound Routes, FollowMe or User Manager?


(Itzik) #4

Normally you would let the PBX generate a password, same with the API.

The API is constantly being worked on (you can start watching these Wiki pages to get notified when there is new changes)
The good new is, AFAIK, the API is open source, so if something is missing that you desperately need, you can write it and then contribute it!


(Jared Busch) #5

Not when you are programmatically creating one. Because whatever system that is creating the extension will have a password it wants to set the extension to that it will use for the OTHER things it is doing.


(Itzik) #6

Woo-hoo! The documentation has been updated:

https://wiki.freepbx.org/display/FPG/Core+Module+GraphQL+APIs

With a new option of:

extPassword: "secret"

API Request

GQLAPI: /admin/api/api/gql
 
Parameters:
 
  mutation {
    updateExtension(
        input: {
            extensionId: 9090090111
            name: "api test"
            tech: "pjsip"
            channelName: "APi Test2"
            outboundCid: "12345678901"
            email: "xyzabc@gmailcom"
            umGroups: "1"
            umEnable: true
            umPassword: "password"
            vmPassword: "password"
            vmEnable: true
            callerID: "234234324"
            emergencyCid: "1221333331"
            clientMutationId: "test1231"
            extPassword: "secret"
        }
      ) {
            status
            message
            clientMutationId
       }
}

API Response

{
  "data": {
    "updateExtension": {
      "status": true,
      "message": "Extension has been updated",
      "clientMutationId": "test1231"
    }
  }
}

GraphQL API query sipsecret
#7

The other reason one might want/need to specify the password is that the organization might have specific password complexity requirements so good to be able to manually specify it.


(United Kingdom) #8

I’ve been looking at how to programmatically set the extension “secret” for some time.
I was delighted when I saw the “extPassword” option. But I can’t get it to work. I get :
“Field “extPassword” is not defined by type updateExtensionInput; Did you mean vmPassword?”
I have updated the PBX API module to 15.0.3.12
Any ideas ?


(Itzik) #9

Make sure you run api and core in latest edge


(United Kingdom) #10

I’m not sure I follow. “Edge” as in the browser ??
I’m developing the GraphQL in Insomina before implementing in a c# desktop app.
I get the same error when using the FreePBX GraphQL explorer in both Chrome and Edge.


(Itzik) #11

Usually, when someone here is referring to edge, they are referring to the edge repository.

https://wiki.freepbx.org/display/FPG/Edge+vs+Stable

fwconsole ma upgrade <module> --edge

(Lorne Gaetz) #12

As @PitzKey says, this is a new feature and requires very new versions of the API and core modules. Update from edge repo.

It’s great to see people actively discussing and using the API we’ve been adding. As I’ve written before, this is one of the focuses for FreePBX 16, and where possible, new 16 features are being backported to previous version(s).


(United Kingdom) #13

Thanks @lgaetz and @PitzKey

I couldn’t get it to offer me the option of using edge repositories - despite setting “Module admin to edge mode”.
However - the problem seems to have disappeared. I can now create extensions with a secret of my choice.
Or so I thought - the secret displayed in the GUI doesn’t seem to have changed.
I would check - but the query I was using to extract the secret has now stopped working :

    tech {
      __typename... on pjsip{secret}
    }

Now returns :

“Field “tech” of type “String!” must not have a sub selection.”

To perhaps clarify what I am trying to do :
The aim is to have an app or web page provision extensions with minimal details. Those details being what a user would enter when logging into a softphone.


(Ricoh) #14

Ran into this too, running
Asterisk 16.17.0
FreePBX 15.0.17.34
PBX API 15.0.3.12


#15

extPassword
I get:

“message”: “Cannot query field “extPassword” on type “coreuser”. Did you mean “password”?”

But “fetchAllExtensions” works with all the other fields


(Itzik) #16

#17

Does not work.
Also tried Greg’s sample code:

{
  fetchExtension(extensionId: "4033") {
    status
    message
    extensionId
    user {      extPassword    }
  }
}

Result:

{
“errors”: [
{
“message”: “Cannot query field “extPassword” on type “coreuser”. Did you mean “password”?”,
“status”: false
}
]
}


(Itzik) #18

Modules on the latest edge version?


#19

Yes. I do “fwconsole ma upgrade --edge framework api certman firewall sysadmin” before I start working every time


(Greg Blumenthal) #20

@yahdie But the modules you need on edge as mentioned in my linked post are core, userman, and api. Your command only had “api” from those 3. Please try it again with core and userman at edge. Just tried it with these versions, still working:

#fwconsole ma list |egrep "core|api|userman"
     | api                  | 15.0.3.15  | Enabled                           | AGPLv3+     
     | core                 | 15.0.12.71 | Enabled                           | GPLv3+      |
     | userman              | 15.0.41    | Enabled                           | AGPLv3+     |