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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am facing the same issue, where you able to resolve this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.