PagerDuty / pdpyras

Low-level PagerDuty REST/Events API client for Python
MIT License
129 stars 29 forks source link

triggering events through EventsAPISession fails #94

Closed ben-polytope closed 1 year ago

ben-polytope commented 1 year ago

Hi,

I'm having some issues using the EventsAPISession object. I've properly instantiated this object with a routing key obtained from the Events API v2 integration attached to my desired service. When calling the 'trigger' method, I get a deduplicate key and even took it a step further by implementing a class that returns the full response object (see below). I can see that my calls are being returned as successful according to the response code of 202 and the response body containing {'message': 'Event processed', 'status': 'success'}.

When I visit the GUI to ensure my incident fired under the desired service, there is no instance of this incident under the service or any other service for that matter. I cannot find any breaking API changes that would be causing this, so unsure how to proceed.

from pdpyras import EventsAPISession, raise_on_error, try_decoding

class EventsAPISessionWrapper(EventsAPISession):
    def send_event(self, action, dedup_key=None, **properties):
        actions = ('trigger', 'acknowledge', 'resolve')
        if action not in actions:
            raise ValueError("Event action must be one of: "+', '.join(actions))

        event = {'event_action':action}

        event.update(properties)
        if isinstance(dedup_key, str):
            event['dedup_key'] = dedup_key
        elif not action == 'trigger':
            raise ValueError("The dedup_key property is required for"
                "event_action=%s events, and it must be a string."%action)
        response = self.post('/v2/enqueue', json=event)
        raise_on_error(response)
        response_body = try_decoding(response)
        if not 'dedup_key' in response_body:
            raise PDClientError("Malformed response body; does not contain "
                "deduplication key.", response=response)
        return response
ben-polytope commented 1 year ago

closing, issue with PagerDuty plan, not pdpyras