GitHub API: get billing quota reset date - api

Is there a GitHub API I can use to retrieve the number of days X in
GitHub Actions
Included minutes quota resets in X days
which you can find on the https://github.com/settings/billing page?
Performing the following API call
# GITHUB_TOKEN with "Update ALL user data" permission
curl \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/users/$GITHUB_USER/settings/billing/actions
I get all info except for the billing period expiration date:
{
"total_minutes_used": 228,
"total_paid_minutes_used": 0,
"included_minutes": 2000,
"minutes_used_breakdown": {
"UBUNTU": 228
}
}
Many thanks.

I've figured out the "number of days left in the billing cycle" can be retrieved from the /users/<user>/settings/billing/shared-storage endpoint.
E.g.
curl \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/users/$GITHUB_USER/settings/billing/shared-storage
returns
{
"days_left_in_billing_cycle": 5,
"estimated_paid_storage_for_month": 0,
"estimated_storage_for_month": 0
}

Related

Azure IoT-Hub Job Query returns to few results

I already successfully scheduled a lot of jobs using the REST API of the Azure IoT-Hub as described in https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-jobs. Namely I scheduled jobs to execute direct methods.
But, when I try to query the status of the scheduled jobs (as described on the same page), I always get only one entry: the status of the first successfully scheduled job. How do I get the status of all jobs?
My query was:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' -o response.json
The SAS Token I used above was the same as for scheduling the job. Thus, there is no authentication issue.
The formatted response just contains 1 entry despite that I already scheduled 11 jobs:
[
{
"jobId": "job02",
"queryCondition": "deviceId = simple_thermostat",
"createdTime": "2022-03-02T15:59:27.4093129Z",
"startTime": "2022-03-02T15:20:15Z",
"endTime": "2022-03-02T15:59:34.5969497Z",
"maxExecutionTimeInSeconds": 10000,
"type": "scheduleDeviceMethod",
"cloudToDeviceMethod": {
"methodName": "getMaxMinReport",
"payload": "hello",
"responseTimeoutInSeconds": 300,
"connectTimeoutInSeconds": 0
},
"status": "completed",
"deviceJobStatistics": {
"deviceCount": 0,
"failedCount": 0,
"succeededCount": 0,
"runningCount": 0,
"pendingCount": 0
}
}
]
PS: Getting the status of a single job works as expected. Like using this request:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/job11?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' -o response.json
But, job11 is never returned in the query above.
As pointed out by Roman Kiss, the continuation token can be found in the header of the first response. To save the header via curl one must specify the option -D. So, the first query must look like:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' \
-D response_hdr.txt -o response.json
Then response_hdr.txt will contain a line like this:
x-ms-continuation: eyJzb3VyY2UiOiJkZGIiLCJ0b3RhbFJldHJpZXZlZENvdW50Ijo4LCJjb250aW51YXRpb25Ub2tlbiI6Ilt7XCJ0b2tlblwiOm51bGwsXCJyYW5nZVwiOntcIm1pblwiOlwiMDVDMUU3RkZGRkZGRkFcIixcIm1heFwiOlwiRkZcIn19XSJ9
But, this continuation token must not be specified in the URL as stated in the Microsoft docs. Instead it must be provided in the header of the subsequent query:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'x-ms-continuation: <continuation_token_from_previous_query>' \
-D response_hdr.txt -o response.json
This query will deliver a new continuation token. It looks pretty similar, but it is not identical.

Paypal Sandbox - "Invalid data provided" when try to add tracking info

I want to add tracking information for PayPal transactions and use examples from docs:
curl -v -X PUT https://api-m.sandbox.paypal.com/v1/shipping/trackers/8MC585209K746392H-443844607820 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <my access token>" \
-d '{
"transaction_id": "8MC585209K746392H",
"tracking_number": "443844607820",
"status": "SHIPPED",
"carrier": "FEDEX"
}
But the response is:
{"errors":[{"name":"INVALID_TRANSACTION_ID","message":"Invalid data provided","debug_id":"4bec***8348","details":[{"field":"#/transaction_id","value":"8MC585209K746392H","location":"body","issue":"INVALID_TRANSACTION_ID"}]}]}
Where is my mistake?
It would seem that is not a payment transaction ID from a capture. Perhaps you are mistakenly passing an Order ID -- which is only used during approval and not persisted nor useful after capture.
The PayPal transaction ID is in the capture response at purchase_units[0].payments.captures[0].id

Keycloak does not refresh the token

I'm trying to refresh a token but Keycloak returns a 400 Bad Request error with following message:
{
"error": "invalid_grant",
"error_description": "Invalid refresh token"
}
I successfully get the refresh token in a request like this:
curl --location --request POST 'http://localhost:8080/auth/realms/my_realm/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=my_user' \
--data-urlencode 'password=my_password' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=my_client_id' \
--data-urlencode 'client_secret=my_client_secret'
So I get a JWT response with access token and refresh token. Both of them appear to be valid as I load them in jwt.io.
But when I try to use the refresh token I get previous error. The request is like this:
curl --location --request POST 'http://localhost:8080/auth/realms/my_realm/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=my_client_id' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'refresh_token=my_refresh_token' \
--data-urlencode 'client_secret=my_client_secret'
In Keycloak's log there is no clue of what the problem is.
Waht could be the cause? Or at least, is there a way to get more info on the cause of the error from Keycloak' response or log?
EDIT:
I have implemented an User Storage Provider SPI so it does the authentication against an external DB but it doesn't manage users into Keycloak. Is it needed that the token owner user exists in Keycloak so refreshing the token works?
Thanks.
Finally it was an issue in my User Storage Provider SPI. It was necessary to implement following method as Keycloak takes the user ID from the refresh token and look for the user by such ID:
public UserModel getUserById(String id, RealmModel realm) {
StorageId storageId = new StorageId(id);
String username = storageId.getExternalId();
return getUserByUsername(username, realm);
}

USER.SUBMIT_FORM_DATA: Event filter Fails for UPDATE Outgoing WebHook call

I can register events with USER.SUBMIT_FORM_DATA no problem, also I can Update (PUT) all the other event filters without errors. USER.SUBMIT_FORM_DATA fails when using PUT to update. Reproduced error in PowerShell, Curl and Postman. I also noticed Swagger does not have USER.SUBMIT_FORM_DATA available in the array. This is what's available:
CONVERSATION.CREATE
CONVERSATION.UPDATE
CONVERSATION.ADD_ITEM
CONVERSATION.UPDATE_ITEM
USER.USER_UPDATED
USER.USER_SETTING_UPDATED
Request:
curl -L -X PUT 'https://circuitsandbox.net/rest/v2/webhooks/IdHere' \
-H 'accept: application/json' \
-H 'authorization: Bearer Token\
-H 'content-type: application/x-www-form-urlencoded' \
--data-urlencode 'url=https://webhook.site/IdHere' \
--data-urlencode 'filter=USER.SUBMIT_FORM_DATA'
Error:
{
"errorDescription": "the request contains invalid data",
"validationErrors": [
"The request array with name ::= [filter] and content value ::=[USER.SUBMIT_FORM_DATA]does not match the expression ::= [CONVERSATION.CREATE||CONVERSATION.UPDATE||CONVERSATION.ADD_ITEM||CONVERSATION.UPDATE_ITEM||USER.USER_UPDATED||USER.USER_SETTING_UPDATED]."
],
"errorCode": "400"
}
Sorry, that is a bug in the endpoint, I added a fix which will be available with the next release.

Uber API "POST /requests/estimate" response POST "code":"unauthorized"

i'll try to get data by following API calling:
Uber API -- POST /requests/estimate
curl -X POST \
-H 'Authorization: Bearer JA.VUNmGAAAAAAAEgASAAAABwAIAAwAAAAAAAAAEgAAAAAAAAG8AAAAFAAAAAAADgAQAAQAAAAIAAwAAAAOAAAAkAAAABwAAAAEAAAAEAAAAHK_p1D73ZBrTyH5MuBCGAhsAAAA28z3l42QLSOiQE_6m1J30O4ZQjwpDR_rVf5o41ONOluUZohTYhXEhHNBCLkDO0mXJV39hE2RkcsIRm9ICi_UMVGESeHsQ_uRsX_yD1EDoUbcdHa0Yhf8XGOJkFz1-IB5x9Ivq6SxHpmREeExDAAAAGRcztTG8GDUTlDYpSQAAABiMGQ4NTgwMy0zOGEwLTQyYjMtODA2ZS03YTRjZjhlMTk2ZWU' \
-H 'Accept-Language: en_US' \
-H 'Content-Type: application/json' \
-d '{
"start_latitude": 37.7752278,
"start_longitude": -122.4197513,
"end_latitude": 37.7773228,
"end_longitude": -122.4272052
}' "https://api.uber.com/v1.2/requests/estimate?scope=request
Response
{"code":"unauthorized","message":"This endpoint requires at least one of the following scopes: profile, request, request.delegate, request.delegate.tos_accept, surge_accept"}%
While Below API are working Fine
/products
/estimates/price
/estimates/time
this is old API. New one looks like this.
GET /v1.2/estimates/price