Creating a team via the API

rest-api

(Robert Ayres) #1

Hi,

I’m trying to create a team via the API. I have some Python code which reads the list of teams and users already created and that works fine. I then tried to make it create a team which failed. To make things simpler I tried it from the command line, pretty much using the curl example in the API docs and it still doesn’t work.

curl -X POST --header “Content-Type: application/json” --header ‘Authorization: XXXXXXXXX’ --header ‘Accept: application/vnd.pagerduty+json;version=2’ -d ‘Team_Name’ ‘https://api.pagerduty.com/teams

The API key is v2 Current, Full access.

Anyone else having similar problems?

Thanks.


(geeth) #2

The two things required to make a team are type and name.

Here’s my example:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=MY_TOKEN' -d '{
  "team": {
    "type": "team",
    "name": "Team Name",
    }
}' 'https://api.pagerduty.com/teams'

Hopefully, this helps give you an idea of what’s needed!


(Robert Ayres) #3

Hi,

Thanks for the reply. I had already tried something similar:

curl -X POST --header “Content-Type: application/json” --header ‘Authorization: XXXXXXXX’ --header ‘Accept: application/vnd.pagerduty+json;version=2’ -d@create_team.json ‘https://api.pagerduty.com/teams

Where create_team.json is:

{“team”: {“type”: “team”, “name”: “teamX”}}

But have no luck with that either. I’ve also tried using other full access API keys with no luck.

Thanks,

Rob


#4

Hi Robert,

I tried to run curl command you’ve posted above and there was one immediate thing that I noticed - the “Authorization” header was missing some syntax.

The correct call would be something like:

curl -X POST --header 'Content-Type: application/json' --header 'Authorization: Token token=xxxxxxxx' --header 'Accept: application/vnd.pagerduty+json;version=2' -d@create_team.json 'https://api.pagerduty.com/teams'

The Token token= is actually required.

The second error which I noticed was that the “Content-Type” header is enclosed in a double-inverted comma’s. I changed it to single one, and now the command seems to be working.

Also, while I was copying and pasting the command from your comments to my terminal, the terminal seemed to mess up with my inverted comma’s again. So I had to take about it. But I am pretty sure you would be good with that.

Please get in touch if you need more help.

Cheers!
Shivinder.


(system) #5

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