0

I have integrated Jenkins CI with pagerduty. Once I do that, I can see intergration key generated. enter image description here

That will be used in jenkins to send the events to pagerduty.

The requirement is to rotate the keys after some time. I want to automate this. Is there any api to regenerate the intergration key and return the key in response to be stored in jenkins?

Adya
  • 58
  • 5

2 Answers2

0

I think the simplest solution here is to use the REST API -- it isn't possible to regenerate the integration key directly, but you can delete the integration and create a new one programmatically.

First fetch the service details:

curl --location --request GET 'https://api.pagerduty.com/services/<service_id>' \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header 'Authorization: Bearer <bearer_token>'

This will include all of the integrations on the service -- make note of the integration_id and the vendor_id.

The delete endpoint isn't documented but it does seem to exist:

curl --location --request DELETE 'https://api.pagerduty.com/services/<service_id>/integrations/<integration_id>' \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header 'Authorization: Bearer <bearer_token>'

And finally you can create the new integration, using the vendor_id from the GET request:

curl --request POST \
  --url https://api.pagerduty.com/services/id/integrations \
  --header 'Accept: application/vnd.pagerduty+json;version=2' \
  --header 'Authorization: Bearer <bearer_token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "integration": {
    "type": "generic_email_inbound_integration",
    "name": "Email",
    "service": {
      "id": "<service_id>",
      "type": "service_reference"
    },
    "integration_email": "my-email-based-integration@subdomain.pagerduty.com",
    "vendor": {
      "type": "vendor_reference",
      "id": "<vendor_id>"
    }
  }
Hannele
  • 9,301
  • 6
  • 48
  • 68
0

On doing inspect element to UI button UI button to regenerate key

Its executing POST API:

https://xxxxxxx.pagerduty.com/api/v1/services/XXXXXXX/integrations/XXXXXXX/regenerate_key
4b0
  • 21,981
  • 30
  • 95
  • 142
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31764721) – Kuro Neko May 18 '22 at 05:36
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 18 '22 at 07:10
  • Are you even trying to answer the question? The fact that you end in "But [I] cannot find ..." seems like you are asking for help. – Yunnosch Sep 07 '22 at 05:43