how to regenerate pagerduty integration key programmatically - pagerduty

I have integrated Jenkins CI with pagerduty. Once I do that, I can see intergration key generated.
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?

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>"
}
}

On doing inspect element to UI button
Its executing POST API:
https://xxxxxxx.pagerduty.com/api/v1/services/XXXXXXX/integrations/XXXXXXX/regenerate_key

Related

ifttt webhook returns 403 (it works with curl)

I want to automatize a task, and the last step is to trigger a webhook on github. I am using ifttt "Make a web request"
This request works with curl
curl --location --request POST 'https://api.github.com/repos/wiso/TemperaturaUfficio/dispatches?event_type=webhook' \
--header 'Accept: application/vnd.github+json' \
--header 'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{
"event_type": "test_webhook"
}'
I am trying to do the same with ifttt:
I get:
Your server returned a 403. Unable to make web request to https://api.github.com/repos/wiso/TemperaturaUfficio/dispatches?event_type=webhook

How to set the secret in Bitbucket Server Create Webhook API call

I have crafted a curl which looks something like this. It successfully creates a webhook in BitBucket Server, however, it does not set the 'secret' value, and because of this when the webhook is triggered it fails with a 'missing signature in header'.
If I manually set the secret value, it will then work.
I have looked through Bitbucket Server documentation for 'Create webhook'
and do not see anything related.
Link for reference:
https://developer.atlassian.com/server/bitbucket/rest/v804/api-group-repository/#api-api-latest-projects-projectkey-repos-repositoryslug-webhooks-post
url --request POST \
--url 'https://git.example.org/rest/api/latest/projects/DP/repos/demo/webhooks' \
--header 'Authorization: Bearer xxx' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"events": [
"repo:refs_changed"
],
"active": true,
"statistics": {},
"configuration": {},
"url": "http://example.org/push",
"name": "Argo Events"
}'
After opening web tools and manually creating the webhook in the BitBucket website, we inspected the network tab and found that it was stored in the configuration object.
Example curl below.
curl --request POST \
--url 'https://example.org/webhooks' \
--header 'Authorization: Bearer xxx' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"events": [
"repo:refs_changed"
],
"active": true,
"statistics": {},
"configuration": {"createdBy": "bitbucket","secret": "password"},
"url": "http://example.org/push",
"name": "Argo Events"
}'

Activate flow using Tooling API

I am trying to activate a flow using Tooling REST API. Documentation indicates that this is possible.
But when I try to do it I get this error in http response body:
"message": "You must provide a valid Metadata field for InteractionDefinitionVersion",
"errorCode": "REQUIRED_FIELD_MISSING",
"fields": []
Here is my curl request:
curl --location --request PATCH 'https://XXX.my.salesforce.com/services/data/v55.0/tooling/sobjects/Flow/3015Y000000YJ7pQAG' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer XXX' \
--data-raw '{
"Status": "Active"
}'

Unable to update couchbase document using POST REST API

I want to update a couchbase document with REST API
ilceabcd1233.corp.abcd.com:8091/pools/default/buckets/{bucketName}/docs/{documentId}
When I hit below CURL command in postman, I receive 200 OK response Code with response as blank json Array: []
CURL:
curl --location --request POST 'ilceabcd1233.corp.abcd.com:8091/pools/default/buckets/{bucketName}/docs/{documentId}' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic QWRtaW5pc3RyYXRvcjpBZG1pbmlzdHJhdG9yff' \
--data-raw '{"name": "Nisarg", "age": 50}'
When I retrieve this document by below CURL:
curl --location --request GET 'ilceabcd1233.corp.abcd.com:8091/pools/default/buckets/{bucketName}/docs/{documentId}' \
--header 'Accept: application/json' \
--header 'Authorization: Basic QWRtaW5pc3RyYXRvcjpBZG1pbmlzdHJhdG9yff'
it responds:
{
"meta": {
"id": "112176152456",
"rev": "4-1637ac65ed7900000000000002000006",
"att_reason": "invalid_json",
"expiration": 0,
"flags": 33554438
},
"base64": "",
"xattrs": {}
}
On Couchbase web console I see message:
"Binary document. Base64 not available"
Can any one please help, what I am doing wrong ?
The trick here is that this API doesn't actually accept JSON. It's looking for application/x-www-form-urlencoded. Otherwise it will assume you are storing a binary document. You actually need a form value, which itself contains JSON. For example:
curl --location --request POST 'http://localhost:8091/pools/default/buckets/demo/docs/doc1' \
--header 'Accept: application/json, text/plain, */*' \
--header 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
--header 'Authorization: Basic QWRtaW5pc3RyYXRvcjpwYXNzd29yZA==' \
--data-urlencode 'value={"foo": "bar"}'
And just to echo my comment, this is an undocumented, unsupported endpoint that's really meant for internal use only. It's recommended instead to use an SDK (like the Couchbase Java SDK, for instance) to read/write documents. The REST API is intended for Cluster management, not for CRUD.

JSON_PARSER_ERROR on PATCH when updating a custom object

I am attempting to update a custom object using the Salesforce REST API as described here, but I consistently receive this 400 response
[
{
"message": "The HTTP entity body is required, but this request has no entity body.",
"errorCode": "JSON_PARSER_ERROR"
}
]
I have tried appending ?_HttpMethod=PATCH to the url and switching to a POSTcall, but while that yields 200 OK, it doesn't actually update the object. The object is "updateable" and I do have permission to edit it. Editing it directly in Salesforce works without issues.
Here is my (cleaned) request, as exported from Insomnia [Version 5.14.9 (5.14.9.1895)].
curl --request PATCH \
--url https://myInstance.salesforce.com/services/data/v20.0/sobjects/CUSTOMOBJECT/CUSTOMOBJECTID \
--header 'authorization: Bearer token' \
--header 'content-type: application/json' \
--data '{
"Additional_Information__c": "Test additional information"
}'
Any ideas on how I can resolve this?
According to the Salesforce documentation for sending HTTP requests with cURL, either a JSON data file needs to be sent or a ".json" extension needs to be appended to the URI.
curl --request PATCH \
--url https://myInstance.salesforce.com/services/data/v20.0/sobjects/CUSTOMOBJECT/CUSTOMOBJECTID.json \
--header 'authorization: Bearer token' \
--header 'content-type: application/json' \
--data '{
"Additional_Information__c": "Test additional information"
}'