Author Topic: Getting Total Trunks with Genesys API  (Read 259 times)

Offline victor

  • Administrator
  • Hero Member
  • *****
  • Posts: 1416
  • Karma: 18
Getting Total Trunks with Genesys API
« 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 :) )


Offline Kubig

  • Hero Member
  • *****
  • Posts: 2752
  • Karma: 44
Re: Getting Total Trunks with Genesys API
« Reply #1 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

Offline nonny

  • Full Member
  • ***
  • Posts: 218
  • Karma: 2
Re: Getting Total Trunks with Genesys API
« Reply #2 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.