GraphQL - addInboundRoute - Fails is "optional" boolean fields are not sent

From reading through the documentation, Core Module GraphQL APIs - PBX GUI - Documentation

I should be able to add an inbound route using Graphql via:

mutation {
    addInboundRoute(input: {
          extension:"3068675309"
          cidnum:"3068675309"
          description:"sholinaty TEST"
          grppre:"SHOLE"
          destination:"ext-queues,999"
    }) {
        inboundRoute {
          id
        }
        status
        message
    }
}

that should have each of the Mandatory fields (Extension, CIDNum, destination)

however, it responds with an HTTP 400, with “Internal Server Error” as the response.

My assumption is that the issue is the Destination, but where/how would I find what to use?
in the example its just a number. but Inbound Routes have several configuration options (dropdowns) and specific data there…

Anyone have a working example of how to get the AddInboundRoute Graphql API working?

Try

destination:"ext-queues,999,1"

first try:

{
    "error": "access_denied",
    "message": "The resource owner or authorization server denied the request.",
    "hint": "Access token is invalid"
}

but that’s because I’m a numpty…

Second (Auth’d) try:

{
    "errors": [
        {
            "message": "Internal server error",
            "status": false
        }
    ]
}

its the weirdest thing. its a Useless error message. if I omit the destination, I get a properly formatted error back with descriptive data…

this is the weirdest thing.
From walking the source code, that API should be adding a line to the SQL table incoming
checking that table, the values I’m sending Should exist (Example off my test server)

Screen Shot 2022-03-08 at 10.38.05 AM

But it gets weirder…
the example is successful:

    addInboundRoute(input: {
          extension:"3068675309"
          cidnum:""
          description:"Lorem Ipsum"
          privacyman:false
          alertinfo:"Lorem Ipsum"
          ringing:true
          mohclass:"default"
          grppre:"SHOL"
          delay_answer:12
          pricid:false
          pmmaxretries:"123"
          pmminlength:"12"
          reversal:true
          rvolume:"12"
          fanswer:true
          destination:"1233"
    }) {
        inboundRoute {
          id
        }
        status
        message
    }
}

except the Destination is garbage…

Maybe the Wiki is wrong and there are more mandatory fields? Use the example and start removing what the Wiki refers to as “Optional” fields and see when it breaks

1 Like

Excitement!
using destination:"app-blackhole,no-service,1" does indeed work.

so now to narrow it down and find out what field is Mandatory even though it shouldn’t be…

its ALL of the Boolean operators!

okay. i can work with this.

if any of the following are missing from the graphql request, the entire request goes belly up.

          privacyman:false
          ringing:true
          pricid:false
          reversal:true
          fanswer:true

@lgaetz is this intended? The Wiki seems to indicate otherwise.

its not.
Something is Broken* in the “Set to Default if its not set”

I’ll get a bug report and pull request in to fix it, probably today.

2 Likes

Specifically… notice that its setting a boolean as an empty string for all of those values? don’t do that.

        public function addDIDDefaults(&$settings) {
                $settings['cidnum'] = isset($settings['cidnum'])?$settings['cidnum']:'';
                $settings['description'] = isset($settings['description'])?$settings['description']:'';
                $settings['fanswer'] = isset($settings['fanswer'])?$settings['fanswer']:'';
                $settings['delay_answer'] = isset($settings['delay_answer'])&&$settings['delay_answer']?$settings['delay_answer']:'0';
                $settings['rvolume'] = isset($settings['rvolume']) && $settings['rvolume'] != '' ? $settings['rvolume'] : '0';
                $settings['privacyman'] = isset($settings['privacyman'])?$settings['privacyman']:'0';
                $settings['pmmaxretries'] = isset($settings['pmmaxretries']) && $settings['pmmaxretries'] != '' ?$settings['pmmaxretries']:'3';
                $settings['pmminlength'] = isset($settings['pmminlength']) && $settings['pmminlength'] != '' ?$settings['pmminlength']:'10';
                $settings['alertinfo'] = isset($settings['alertinfo'])?$settings['alertinfo']:'';
                $settings['ringing'] = isset($settings['ringing'])?$settings['ringing']:'';
                $settings['reversal'] = isset($settings['reversal'])?$settings['reversal']:'';
                $settings['mohclass'] = isset($settings['mohclass'])?$settings['mohclass']:'default';
                $settings['grppre'] = isset($settings['grppre'])?$settings['grppre']:'';
                $settings['pricid'] = isset($settings['pricid'])?$settings['pricid']:'';
                $settings['rnavsort'] = isset($settings['rnavsort'])?$settings['rnavsort']:'description';
                $settings['didfilter'] = isset($settings['didfilter'])?$settings['didfilter']:'';
                $settings['indication_zone'] = isset($settings['indication_zone'])?$settings['indication_zone']:'default';
        }

man… who Wrote this…
the graphql API:
runs “add DID Defaults” on an empty array
then calls a function… that calls AddDIDDefaults with the input values (use input value if set…) a second time…

Still not sure yet why its failing if any of those boolean fields arent set in the request. it doesn’t make sense.

good lord… who wrote this code…

… inputs = inputs
defaults = blank array
defaults = fetch the defaults
for each field in defaults, if not set in input, set it to the default (so now, Input = input, or Default if not set)
then MERGE the defaults and input for some reason
then call addDID, which fetches the “set or default” a 2nd time

Theres like 8 extra steps that arent needed here.

giving up.
please see [FREEPBX-23376] AddInboundRoute Graphql API optional fields are mandatory - Sangoma Issue Tracker for bug report.
I’ve tried, but this hot garbage is beyond what I have the time to fix. maybe @lgaetz knows someone crazy enough to try and fix it :stuck_out_tongue:

tldr: the boolean fields are all Mandatory, whether the docs say it or not. because this code is… no bueno.

I appreciate your use of “hot garbage” in both this post and the bug report :rofl:

1 Like

… its been a bad day… sorry about that.
One of our sip trunk providers migrated us to a new platform with maybe 30% the functionality of the old one, and now all my backlogged tasks are “Urgent” and blocked.

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