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,551,927
Community Members
 
Community Events
184
Community Groups

incident_api.create_incident fails with Unauthorized, but same REST with Postman works

When posting with Postman, it works fine, but when I try to create an incident with the Python API, I get:

opsgenie_sdk.exceptions.AuthenticationException: You are not authorized to perform this action: (401)
Reason: Unauthorized: apiKey is invalid or integration is disabled

Here is a super simplified version of the python, opsgenie_api_key is just the guid without the 'GenieKey ' prefix:

def simple_create_incident(opsgenie_api_key, message='Alert', description='Description', priority='P5', asynchronous=False):
create_response, request_id = None, None
conf = opsgenie_sdk.configuration.Configuration()
conf.api_key['Authorization'] = opsgenie_api_key
api_client = opsgenie_sdk.api_client.ApiClient(configuration=conf)
incident_api = opsgenie_sdk.IncidentApi(api_client=api_client)
asc_time = time.asctime()
message = f'{message} @ {asc_time}'
body = opsgenie_sdk.CreateIncidentPayload(message=message, description=description, priority=priority)
if asynchronous:
thread = incident_api.create_incident(create_incident_payload=body, async_req=True)
create_response = thread.get()
else:
create_response = incident_api.create_incident(create_incident_payload=body)
request_id = incident_api.api_client.last_response.getheader('X-Request-ID')
return create_response or request_id

 

1 answer

0 votes
Justin Sitarz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Jun 09, 2021

Hi Matt!

 

The error response you're getting *usually* indicates that the API key you're using is incorrect or has been deleted or rotated in your Opsgenie account. Using your example code, I was able to set that up and successfully generate new incidents, when using an api key generated from the 'API Key Management' section of the app, granted with the 'Create and Update' rights. 

 

Could I have you generate a new API key in your account with those rights granted, and test it out once again? If you're still getting the same error, please let me know, and I we can take a closer look. 

 

Thanks!

 

Justin

Hi Justin,

 

I am facing the same issue as above. 

I have created a new API key with 'Create and Update' rights. Using this key iam getting the below exception.

opsgenie_sdk.exceptions.AuthenticationException: You are not authorized to perform this action: (403)

 

Can you please help me with this?

 

Thanks,

Kartik

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events