Query users by team id

users
teams
rest-api
questions

(Nathan Falk) #1

Hi,

I’m working on a program for updating schedules in Pagerduty. Basically, the program will take a text file as input, containing the date and the name of the duty programmer, and will use a PUT to update the schedule.

The program is written in python, but I’m starting out by playing around with curl commands. I think I’ve figured out the quirks of updating the schedule itself, but the piece I’m stuck on now is mapping user names to IDs, so I can provide the IDs when I update the schedule. I’d like to be able to query users by team ID, but when I try, I get back all of the users, not just those users on my team.

curl -H “Accept: application/vnd.pagerduty+json;version=2” -H “Authorization: Token token=” -X GET ‘https://api.pagerduty.com/users?team_id=P448VD9

Any suggestions about how I can limit the results of this query to only those users belonging to a particular team?

Thanks in advance!

Nate Falk


(Nathan Falk) #2

I think I’ve partly answered my own question, by finding this example on the main developer page:

curl -G -H “Authorization: Token token=y_NbAkKc66ryYTWUXYEu”
-H “Accept: application/vnd.pagerduty+json;version=2”
–data-urlencode “statuses[]=triggered”
–data-urlencode “statuses[]=acknowledged”
https://api.pagerduty.com/incidents

(Hiding in plain sight, that was…)

I changed my own request to:

curl -H “Accept: application/vnd.pagerduty+json;version=2” -H “Authorization: Token token=” -X GET --data-urlencode “team_ids[]=P448VD9” ‘https://api.pagerduty.com/users

And that got me my (partial) list. Now to figure out the whole paging thing and getting the rest of the data…

Thanks,

Nate Falk


(Chiedu Uraih) #3

Hello Nate,

What you can do is add ?limit=100 to the cURL request.

Please do let if you have further questions.

Thanks.


(Jonathan Curry) #4

To expand on that, setting limit to 100 will increase the number of results returned by the API from 25 (the default) to 100 (the maximum). If more than 100 results are available (which you’ll know if the value of more is true) you can change to the next page by passing an offset value with your request.

You can find out more about pagination in the API here: https://v2.developer.pagerduty.com/docs/pagination


(Nathan Falk) #5

Thank you Jonathon. I’ll play around with that some more.


(system) #6