Paypal Preapproval invalid request - paypal

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"

Related

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"

Datadog keeps creating monitors when dynamic source id changes

I have a Datadog monitor generated by terraform.
The main query is as follows:
sum(last_1m):avg:app.application.health{application.health:healthy,cluster_name:${local.eks_cluster_name},!source:api-service-full} by {source}.as_count() < 60"
The issue is that after a system restart the {source} container changes it's name.
For example from app-tier-1-1abc-agent
to app-tier-1-def2-agent
The Datadog instead of updating, or removing the old monitors just creates new ones and leaves the old monitors in Alarm and N/A.
Is there anyway to improve this? All ideas appreciated, thanks!
Solved this by sending API calls to edit each monitor query on shutdown and startup.
I made a very clunky bash script, because I couldn't find a way to store -data for the curl in a variable in bash, but if using other scripting languages this could have been done in much less code, example is for 2 monitors
monitor_id=$(curl -L -X GET "https://api.datadoghq.com/api/v1/monitor" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DATADOG_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DATADOG_APP_KEY}" \
--data-raw '{"tags":["application_id:'$APP_ID_LOWERCASE'"]}'| jq -r ' .[] | select((.name |endswith("XXXXXXX Heartbeats") or endswith("XXXXX HeartBeat monitoring")) and (.tags[]=="application_id:'$APP_ID_LOWERCASE'")) | .id')
# curl gets cluster name used in queries
CLUSTER_NAME=$(curl -L -X GET "https://api.datadoghq.com/api/v1/monitor" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DATADOG_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DATADOG_APP_KEY}" \
--data-raw '{"tags":["application_id:'$APP_ID_LOWERCASE'"]}'| jq -r ' .[] | select((.name |endswith("XXXX HeartBeat monitoring")) and (.tags[]=="application_id:'$APP_ID_LOWERCASE'")) | .query' | awk -F',cluster_name:|,' '{print $2}')
# For each monitor id edit monitor query
while IFS= read -r monitors
do
# curl gets monitor name
monitor_name=$(curl -L -X GET "https://api.datadoghq.com/api/v1/monitor/"$monitors"" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "DD-API-KEY: ${DATADOG_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DATADOG_APP_KEY}" | jq -r .name)
# checking which monitor query to send based on name, the queries are hardcoded because I couldn't find a way to set the query as a variable in bash
if [[ $monitor_name == *"XXXXXX HeartBeat monitoring"* ]]; then
shutdown_query=$(curl -L -X PUT "https://api.datadoghq.com/api/v1/monitor/"$monitors"" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DATADOG_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DATADOG_APP_KEY}" \
--data-raw '{"query":"sum(last_1m):avg:health{application.health:healthy,cluster_name:'${CLUSTER_NAME}',!source:XXXXXX-full-1,source:DUMMY-VALUE-TO-RESEt-QUERY} by {source}.as_count() < 60"}')
elif
[[ $monitor_name == *"XXXXXX Instance Heartbeats"* ]]; then
shutdown_query=$(curl -L -X PUT "https://api.datadoghq.com/api/v1/monitor/"$monitors"" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DATADOG_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DATADOG_APP_KEY}" \
--data-raw '{"query":"sum(last_1m):avg:heartbeat{cluster_name:'${CLUSTER_NAME}',source:DUMMY-VALUE-TO-RESEt-QUERY} by {source}.as_count() < 3"}')
fi
done <<< "$monitor_id"
Then just remove the dummy query value on startup and it will pick up your new monitors while forgetting the non existing ones

PagerDuty API get all incidents for a specific day

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!

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.

Specify multiple scopes in PayPal RequestPermission API

Looking at the RequestPermissions API, it says that the scope is supposed to be a string. However, I have been unsuccessful in finding out how to specify more than one scope (specifically EXPRESS_CHECKOUT and REFUND). Comma-separated, semi-colon, and even using their NVP list syntax didn't work. A CURL sample would be greatly appreciated.
Comma-separated example...
curl -s --insecure -H
"X-PAYPAL-SECURITY-USERID: API_USERNAME"
-H "X-PAYPAL-SECURITY-PASSWORD: API_PASSWORD"
-H "X-PAYPAL-SECURITY-SIGNATURE: API_SIGNATURE"
-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/Permissions/RequestPermissions -d
"requestEnvelope.errorLanguage=en_US&scope=EXPRESS_CHECKOUT,REFUND&callback=http://my/callback"
When I make that request, I get back "Invalid request parameter scope with value EXPRESS_CHECKOUT,REFUND"
Ok. Found the answer randomly. The scope variables must be set using "scope(0)=SCOPE_1&scope(1)=SCOPE_2..."
So, the cURL request would look like this...
curl -s --insecure -H
"X-PAYPAL-SECURITY-USERID: API_USERNAME"
-H "X-PAYPAL-SECURITY-PASSWORD: API_PASSWORD"
-H "X-PAYPAL-SECURITY-SIGNATURE: API_SIGNATURE"
-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/Permissions/RequestPermissions -d
"requestEnvelope.errorLanguage=en_US&scope(0)=EXPRESS_CHECKOUT&scope(1)=REFUND&callback=http://my/callback"
If you're using their JSON API, scope can be an array.