PagerDuty API get all incidents for a specific day - rest

I would like to retrieve all PagerDuty incidents that have occurred on a specific day via the API. I am using the following GET request:
curl -i -H "Content-type: application/json" \
-H "Authorization: Token token=wouldntyouliketoknow" \
-X GET \
--data-urlencode "since=2016-05-03T00:00Z" \
--data-urlencode "until=2016-05-03T23:59Z" \
--data-urlencode "offset=100" \
"https://my.pagerduty.com/api/v1/incidents"
There is just one issue with the data that is returned. The timestamps of the returned incidents indicate that the incidents are for different dates, just not the one I specified in the since and until parameters. I checked via the UI that there are more than 100 incidents for the specified date.
How should I modify my query to return all incidents for the specified date?

The time you are specifying is in UTC. My guess is you are in another timezone, which is making the results look incorrect.
The dates are specified in the ISO 8601 format (as per PagerDuty's Developer documentation), so you could specify the date and time with timezone (assuming UTC-7) like so:
2016-05-03T23:59-07
If you are in, say UTC+3, you'd use:
2016-05-03T23:59+03
PagerDuty's API returns at most 100 records, but varies per endpoint, so you'll need to increment the offset parameter and make an API call per page.
For the first 100:
curl -i -H "Content-type: application/json" \
-H "Authorization: Token token=wouldntyouliketoknow" \
-X GET \
--data-urlencode "since=2016-05-03T00:00Z" \
--data-urlencode "until=2016-05-03T23:59Z" \
--data-urlencode "limit=100" \
"https://my.pagerduty.com/api/v1/incidents"
For the second 100:
curl -i -H "Content-type: application/json" \
-H "Authorization: Token token=wouldntyouliketoknow" \
-X GET \
--data-urlencode "since=2016-05-03T00:00Z" \
--data-urlencode "until=2016-05-03T23:59Z" \
--data-urlencode "limit=100" \
--data-urlencode "offset=100" \
"https://my.pagerduty.com/api/v1/incidents"
Cheers!

Related

Adding filter with curl for github api

How do i add the 2fa filter in curl for the github api?Here is an image of the documentation page, however it does not specify how to add the filter for 2fa.
Thanks so much!
I have tried using a "?":
curl
-H "Accept: application/vnd.github+json"
-H "Authorization: Bearer """
-H "X-GitHub-Api-Version: 2022-11-28"
https://api.github.com/orgs/"my_org_name"/members?2fa_disabled
According to the documentation, the query-parameter you need is called filter with the value 2fa_disabled. Therefore your curl command should look the following:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/ORG/members?filter=2fa_disabled
Keep in mind that this options is only available for organization owners.
Documentation: https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#list-organization-members

Github REST Api get workflow runs for a specific date range with cURL

I am trying to query Github's REST API to list workflow runs for specific date ranges.
Here's an example curl call:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/[OWNER]/[REPO]/actions/runs?created:2023-01-01..2023-01-02"
From what I understand from the documentation, this is how I should be able to retrieve only results from Jan 1st and 2nd of 2023. But it does not work, my result is always the latest runs.
What am I doing wrong?
you should use the = symbol instead of :, like:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/[OWNER]/[REPO]/actions/runs?created=2023-01-01..2023-01-02"

How to pass argumets to RunDeck Run API

I want to run a rundeck job using the run API. Would like to pass few parameters as well to the runDeck job during the run time.
Do I need to configure the job to accept parameters?
How to pass parameters to run API?
Thanks in advance
Regards
SJ
Option 1: In absence of tokens, first login to get cookie
curl \
-D - \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Cache-Control: no-cache" \
-d "j_username=${RD_USER}&j_password=${RD_PASSWORD}" \
--cookie-jar rd_cookie \
"${RD_URL}/j_security_check"
Then, use the cookie received from successful login for subsequent transactions
curl \
-D - \
-X "POST" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{\"argString\":\"-arg1 val1 -arg2 val2 -arg3 val-3 -arg4 val4 \"}" \
--cookie "#rd_cookie" \
"${RD_URL}/api/16/job/${RD_JOB_ID}/executions"
Option 2: With a token, it's simpler
curl \
-D - \
-X "POST" -H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-Rundeck-Auth-Token: ${RD_TOKEN}" \
-d "{\"argString\":\"-arg1 val1 -arg2 val2 -arg3 val-3 -arg4 val4 \"}" \
"${RD_URL}/api/16/job/${RD_JOB_ID}/executions"
The API documentation for Rundeck describes how to run a job:
http://rundeck.org/docs/api/#running-a-job
Yes you need to create a parametrized job and pass in arguments as part of the API call. This could be considered a security measure only expected parameters can be accepted.

Paypal Preapproval invalid request

I'm trying to play with the PreApproval from Adaptive Payments. Specifically, to go through the four steps from the documentation on Preapproval.
I'm stuck at the Step 1: Set Up the Preapproval with a curl command:
$ curl -s --insecure \
-H "X-PAYPAL-SECURITY-USERID: myuserid.gmail.com" \
-H "X-PAYPAL-SECURITY-PASSWORD: mypass" \
-H "X-PAYPAL-SECURITY-SIGNATURE: mysignaturestring" \
-H "X-PAYPAL-REQUEST-DATA-FORMAT: NV" \
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: NV" \
-H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" \
https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval -d \
"cancelUrl=http://www.yourdomain.com/cancel.html
&currencyCode=USD
&endingDate=2014-09-10T22:00:00Z
&maxAmountPerPayment=200.00
&maxNumberOfPayments=30
&maxTotalAmountOfAllPayments=1500.00
&pinType=NOT_REQUIRED
&requestEnvelope.errorLanguage=en_US
&returnUrl=http://www.yourdomain.com/success.html
&startingDate=2014-08-10T22:00:00Z"
Instead of a preapprovalKey, I receive an error. I know it's something wrong with the data I send, but I can't figure out what:
esponseEnvelope.timestamp=2014-08-05T01:24:55.289-07:00
&responseEnvelope.ack=Failure
&responseEnvelope.correlationId=7c6db7beda57a
&responseEnvelope.build=11853342
&error(0).errorId=580001
&error(0).domain=PLATFORM
&error(0).subdomain=Application
&error(0).severity=Error
&error(0).category=Application
&error(0).message=Invalid request: Data validation warning(line -1, col 0): 2014-09-10T22:00:00Z
&error(0).parameter(0)=Data validation warning(line -1, col 0): 2014-09-10T22:00:00Z
Please note that:
my API credentials are OK, I've successfully tested them on Express Checkout from the documentation
some fields are according to documentation while others are exactly like in the docs copy pasted:
startingDate is in the future, the docs say to not be today's date (the date of the post) or after end date.
endingDate - startingDate is one month, less than a year as they say in the docs.
I also tried using https://apigee.com/console/paypal in case I was doing sth wrong with curl
Damn, I figured it out due to my indentation on SO to have it look pretty for you guys. It's because of the whitespace enters (\n's) in the -d \ "cancelUrl=... &currencyCode=USD & ...".
Thanks, so the correct one for reference here is:
$ curl -s --insecure \
-H "X-PAYPAL-SECURITY-USERID: myuserid.gmail.com" \
-H "X-PAYPAL-SECURITY-PASSWORD: mypass" \
-H "X-PAYPAL-SECURITY-SIGNATURE: mysignaturestring" \
-H "X-PAYPAL-REQUEST-DATA-FORMAT: NV" \
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: NV" \
-H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" \
https://svcs.sandbox.paypal.com/AdaptivePayments/Preapproval -d \
"cancelUrl=http://www.yourdomain.com/cancel.html&currencyCode=USD&endingDate=2014-09-10T22:00:00Z&maxAmountPerPayment=200.00&maxNumberOfPayments=30&maxTotalAmountOfAllPayments=1500.00&pinType=NOT_REQUIRED&requestEnvelope.errorLanguage=en_US&returnUrl=http://www.yourdomain.com/success.html&startingDate=2014-08-10T22:00:00Z"

Setting Query Parameter on MongoHQ beta API

I'm using the beta api on MongoHQ.com to query a database I set up earlier this week.
I can retrieve the list of databases on my account, the collections in each database and the documents in each collection using the basic URLs.
However, when I try to set a query, limit, fields, etc parameter, it's returning a 404 error.
This is the curl command I'm using:
curl -i -X GET 'https://beta-api.mongohq.com/mongo/<deployment id>/<database name>/collections/<collection name>/documents?query={"name": "Name"}' \
-H 'Content-Type: application/json' -H 'Authorization: api-key <API KEY>'
According to the documentation on the site here - https://docs.mongohq.com/mongohq-api-beta/mongodb-documents.html - the query has to be a "URL encoded MongoDB Extended JSON document". Unfortunately there are no examples of this.
How would I convert the query document above to a URL encoded one?
You can use curl to urlencode your query like this:
curl -i -X GET 'https://beta-api.mongohq.com/mongo/<deployment id>/<database name>/collections/<collection name>/documents' \
-G --data-urlencode 'query={"name": "Name"}' \
-H 'Content-Type: application/json' -H 'Authorization: api-key <API KEY>'
If you use operators like e.g. $gt, be sure to put double quotes around them:
curl -i -X GET 'https://beta-api.mongohq.com/mongo/<deployment id>/<database name>/collections/<collection name>/documents' \
-G --data-urlencode 'query={"value": { "$gt" : 10}}' \
-H 'Content-Type: application/json' -H 'Authorization: api-key <API KEY>'