Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,466,228
Community Members
 
Community Events
176
Community Groups

Issue using API for creating Schedules automatically

I have being tryng to create schedules automatically via python but I cannot, I have already been able to get the data but not to post, I am using the documentation which does not help much. When I try to post i receive the error 405, any suggestion?

1 answer

0 votes
Hana Kučerová Community Leader Jul 04, 2022

Hi @Octavio Ornelas ,

would you please share the code with us, so we can help you with it? Thank you.

import requests
from requests.structures import CaseInsensitiveDict
from pandas import DataFrame, DateOffset, to_datetime

url = <url of the schedule>

headers = CaseInsensitiveDict()
headers["Authorization"] = "GenieKey <API KEY>"
headers["content-Type"] = "application/json"

resp = requests.post(url, headers = headers, json = <body os the schedule>)

print(resp.status_code)

 

BODY of the schedule

{'name': 'Factory Support - Space On-Call Schedule',
'description': 'On-call Schedule for Space Segment (Time Zone is EET)',
'timezone': 'Europe/Helsinki',
'enabled': True,
'ownerTeam': {'name': 'Factory Support - Space'},
'rotations' :{
'name': 'Week 30',
'startDate': '2022-07-25T15:00:00Z',
'endDate': '2022-07-31T07:00:00Z',
'type': 'weekly',
'length': 1,
'participants': [{'type': 'user',
'id': '60a0f278-cb62-4809-800d-ed5e7f483159'}],
'timeRestriction': {'type': 'weekday-and-time-of-day',
'restrictions': [{'startDay': 'monday',
'endDay': 'tuesday',
'startHour': 18,
'endHour': 10,
'startMin': 0,
'endMin': 0},
{'startDay': 'tuesday',
'endDay': 'wednesday',
'startHour': 18,
'endHour': 10,
'startMin': 0,
'endMin': 0},
{'startDay': 'wednesday',
'endDay': 'thursday',
'startHour': 18,
'endHour': 10,
'startMin': 0,
'endMin': 0},
{'startDay': 'thursday',
'endDay': 'friday',
'startHour': 18,
'endHour': 10,
'startMin': 0,
'endMin': 0},
{'startDay': 'friday',
'endDay': 'monday',
'startHour': 18,
'endHour': 10,
'startMin': 0,
'endMin': 0}]}}}

 

I get the response 405 I was thinking that maybe the body has an error but the format is exactly the same as the one shown in the documentation

Hana Kučerová Community Leader Jul 05, 2022

Thank you @Octavio Ornelas . According to the documentation, the POST request needs to be send to https://api.opsgenie.com/v2/schedules, but you are using schedule URL, so maybe your URL is not right?

I tried using this https://api.opsgenie.com/v2/schedules i got the 422 error 

Hana Kučerová Community Leader Jul 05, 2022

According to the documentation error 422 means "Semantic errors in request body"

In JSON there should be double quotes instead of single quotes:

{  "name": "ScheduleName",  "description": "ScheduleDescription",  "timezone": "Europe/Kirov",  "enabled": true,  "ownerTeam": {  "name": "ops_team"  },  "rotations": [  {  "name": "First Rotation",  "startDate": "2017-02-06T05:00:00Z",  "endDate": "2017-02-23T06:00:00Z",  "type": "hourly",  "length": 6,  "participants": [  {  "type": "user",  "username": "user@opsgenie.com"  },  {  "type": "none"  },  {  "type": "user",  "id": "ac463592-dbd2-4ca3-alp1d-48fhf5j5c871"  }  ],  "timeRestriction": {  "type" : "weekday-and-time-of-day",  "restrictions" : [  {  "startDay" : "monday",  "startHour" : 8,  "startMin" : 0,  "endDay" : "tuesday",  "endHour" : 18,  "endMin" : 30  },  {  "startDay" : "wednesday",  "startHour" : 8,  "startMin" : 0,  "endDay" : "thursday",  "endHour" : 18,  "endMin" : 30  }  ]  }  }  ] }

Would you please try to change it?

I changed the quotess and stil gives me the same response 422

Hana Kučerová Community Leader Jul 05, 2022

@Octavio Ornelas Are you able to get also error message what's wrong with the request body, not only error code?

it says --rotations is invalid which i assume means tht the dict rotations has a non expected value, this is the dict i am using

"rotations" :{
"name": "Week 30",
"startDate": "2022-07-25T15:00:00Z",
"endDate": "2022-07-31T07:00:00Z",
"type": "weekly",
"length": 1,
"participants": [{"type": "user",
"username": "<user_name"}],
"timeRestriction": {"type": "weekday-and-time-of-day",
"restrictions": [{"startDay": "monday",
"endDay": "tuesday",
"startHour": 18,
"endHour": 10,
"startMin": 0,
"endMin": 0},
{"startDay": "tuesday",
"endDay": "wednesday",
"startHour": 18,
"endHour": 10,
"startMin": 0,
"endMin": 0},
{"startDay": "wednesday",
"endDay": "thursday",
"startHour": 18,
"endHour": 10,
"startMin": 0,
"endMin": 0},
{"startDay": "thursday",
"endDay": "friday",
"startHour": 18,
"endHour": 10,
"startMin": 0,
"endMin": 0},
{"startDay": "friday",
"endDay": "monday",
"startHour": 18,
"endHour": 10,
"startMin": 0,
"endMin": 0}]}}}

Hana Kučerová Community Leader Jul 06, 2022

Yes, it means something is wrong with this part of JSON, but I cannot tell what exactly. Please try to experiment a little bit with it to find it out.

I have already found the bug but I have another issue when I am trying to update the schedule I cant do it I have the response 409 

<Response [405]>
{'message': "Request method 'POST' not supported", 'took': 0.001, 'requestId': 'c7a2aff3-3c27-4551-b248-e33c8bab846e'}

The code is the same iI just changed the id of the schedule to be updated in the url as the documentation says

url = "https://api.opsgenie.com/v2/schedules/1743f25-c16b-42e0-b017-3a8277410fda

Hana Kučerová Community Leader Jul 10, 2022

Hi @Octavio Ornelas ,

according to the documentation you need to send PATCH request (not POST) to update the schedule.

Hi! I was able to do it by using post, there was a mistake in the dictionary I was using, fortunately the bug was found 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS

Atlassian Community Events