Genesys CTI User Forum

Genesys CTI User Forum => Genesys CTI Technical Discussion => Topic started by: victor on August 28, 2024, 03:35:14 AM

Title: Getting Total Trunks with Genesys API
Post by: victor on August 28, 2024, 03:35:14 AM
Is there a simple way to get the count of active trunks using API?

I would imagine something like this:


```
import requests

url = "https://api.mypurecloud.com/api/v2/telephony/providers/edges/trunks"
headers = {
    "Authorization": "Bearer MY_SUPER_SECRET_TOKEN",
    "Content-Type": "application/json"
}

response = requests.get(url, headers=headers)
trunks = response.json().get("entities", [])

# Count the number of trunks that are connected
active_trunks = sum(1 for trunk in trunks if trunk.get("connectedStatus") == "connected")

print(f"Total number of active trunks: {active_trunks}")
```

But for the life of me, this does not give me what I want. Where am I going wrong? (Other than the use of "sum" and "for" together - don't kill me :) )

Title: Re: Getting Total Trunks with Genesys API
Post by: Kubig on August 28, 2024, 02:56:00 PM
As far as I know there is no other way how to get number of active (connected) trunks
Title: Re: Getting Total Trunks with Genesys API
Post by: nonny on October 24, 2024, 06:55:18 PM
An old thread but you may have to build this up by first getting the list of all trunks then a for:each type loop on them incrementing a count when  state = active.