Empty result of search - youtube-data-api

Use code:
curl \
'https://www.googleapis.com/youtube/v3/search?
part=snippet&channelId=UCsA_vkmuyIRlYYXeJueyIJQ&eventType=live&maxResults=25&type=video&key=[MY_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
and in result:
{
"kind": "youtube#searchListResponse",
"etag": "\"8jEFfXBrqiSrcF6Ee7MQuz8XuAM/yWfRov5-ZkSn3_LbWvrsAvAhhaY\"",
"regionCode": "RU",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 25
},
"items": []
}
Broke today. Yesterday everything worked correctly.

Related

Get zabbix graph to png via API

I have a login script as follows:
curl --location --request POST 'https://zabbixUrl.com/api_jsonrpc.php' \
--header 'Authorization: Basic bWlndWVsLmh1cnRhZG86MTczM295ZmQxVg==' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "user",
"password": "pass"
},
"id": 1
}'
Which returns:
{"jsonrpc":"2.0","result":"1g1hd43j4d3jd4jsl4n35b4211n1d2e2","id":1}
With this Api token (result), I can execute all the Zabbix's methods, for instance:
curl --location --request POST 'https://zabbixUrl.com/api_jsonrpc.php' \
--header 'Authorization: Basic bWlndWVsLmh1cnRhZG86MTczM295ZmQxVg==' \
--header 'Content-Type: application/json' \
--data-raw '
{
"jsonrpc": "2.0",
"method": "screenitem.get",
"params": {
"output": "extend",
"screenids": "258"
},
"auth": "1g1hd43j4d3jd4jsl4n35b4211n1d2e2",
"id": 1
}'
Now I am trying to obtain a graph in PNG format. I can view this graph in PNG format after inserting the user and pass in the intermediate screen:
Now what I am trying to do is to get this PNG graph via API. My approach is the following (ps: the url included is the same one as the one used on the browser, where it does work):
curl --header 'Authorization: Basic bWlndWVsLmh1cnRhZG86MTczM295ZmQxVg==' --data-raw 'auth:1g1hd43j4d3jd4jsl4n35b4211n1d2e2' http://zabbixUrl.com/chart2.php?graphid=123456&period=604800&stime=1614012539
Using this form, I get a 401 error. I guess that it is not correctly detecting the token.
Therefore, my question is, how can I obtain the PNG of this Zabbix's graph via API? How can I do it so it correctly detects the token?
When you authenticate to the API you use a token, when you authenticate to the GUI you need a cookie. Using curl, you need the --cookie option, see Save cookies between two curl requests.
In python requests, you would use a Session: see zabbix-gnomes's zgetgraph.py for a python solution.
A working example in Zabbix 5.0:
auth=$(curl -s --data '{ "jsonrpc": "2.0", "method": "user.login", "params": { "user": "...", "password": "..." }, "id": 1 }' --header 'Content-Type: application/json' https://.../zabbix/api_jsonrpc.php | jq -r .result)
curl --cookie "zbx_sessionid=$auth" "https://.../zabbix/chart2.php?graphid=517&from=now-2d&to=now&height=201&width=1717&profileIdx=web.charts.filter&_=up0bkgs0" -o file.png
I found the solution:
import requests
import json
import shutil
​
##### GET CREDENTIALS #####
​
USER = "user"
PASSWORD = "pass"
URL_AUTH = "https://url.com/api_jsonrpc.php"
HEADER_AUTH = {
'Authorization': 'Basic bWlndWVsLmh1cnRhZG86MTczM295ZmQxVg==',
'Content-Type': 'application/json',
}
DATA_AUTH = """
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "%s",
"password": "%s",
"userData": true
},
"id": 1
}
""" % (USER, PASSWORD)
respAuth = requests.post(URL_AUTH, headers=HEADER_AUTH, data=DATA_AUTH)
zabbixSessionId = json.loads(respAuth.content.decode('utf8').replace("'", '"'))["result"]["sessionid"]
##### GET PNG #####
URL_CHART = "https://url.com/chart2.php?graphid=12345&period=7200"
HEADER_CHART = {
'Authorization': 'Basic bWlndWVsLmh1cnRhZG86MTczM295ZmQxVg==',
'Content-Type': 'image/png',
'Cookie': 'zbx_sessionid=%s' % (zabbixSessionId)
}
PNG_PATH = "./image.png"
respChart = requests.request("POST", URL_CHART, headers=HEADER_CHART, stream=True)
with open(PNG_PATH, 'wb') as out_file:
shutil.copyfileobj(respChart.raw, out_file)

Square Insufficient permissions to set app_fee_money when creating a payment

I used Square Oauth to obtain merchant_access_token using the scopes
CUSTOMERS_WRITE
CUSTOMERS_READ
ITEMS_WRITE
ITEMS_READ
MERCHANT_PROFILE_WRITE
MERCHANT_PROFILE_READ
ORDERS_WRITE+ORDERS_READ
PAYMENTS_WRITE
PAYMENTS_READ
PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS
from https://developer.squareup.com/docs/payments-api/take-payments-and-collect-fees
When I run the command, I get Insufficient permissions to set app_fee_money
I tried this from both the Application as well as Postman
What am I doing wrong?
curl --location --request POST 'https://connect.squareupsandbox.com/v2/payments' \
--header 'Square-Version: 2021-01-21' \
--header 'Authorization: Bearer merchant_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
"source_id": "ccof:customer-card-id-ok",
"idempotency_key": "6726cbd2-7893-4cc3-908e-c54731e9f1fe77979",
"amount_money": {
"amount": 5000,
"currency": "USD"
},
"app_fee_money": {
"amount": 1220,
"currency": "USD"
},
"customer_id": "676YFJE8CCRPZ2K7F9C155JYP8",
"location_id": "LG5CC4T0JXCX9", //Merchant location id
"order_id": "M4C0LcxaW6DNpbyxE7sLypvbFA8zb4F",
"reference_id": "M4C0LcxaW6DNpbyxE7sLypvbFA8zb4F",
"statement_description_identifier": "Organization name",
"note": "Fee note"
}'
PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS was in the code but older version of scopes without it was running, that fixed it. Thanks #sjosey

Bash Script: Error when using variable in curl data

I've been working on creating a script utilizes curl and variables. Doing some searches I found how to place a variable in the data portion of the curl but now I'm getting errors from the curl command.
(Some parts of the code removed to keep passwords out, everything is working except for entering the data into the --data portion of curl)
curlData=$(cat <<EOF
{
"rebootClient": false,
"createPseudoClientRequest": {
"registerClient": true,
"clientInfo": {
"clientType": 0,
}
},
"packages": [
{
"packageId": 702,
"packageName": "File System",
"packageId": 51,
"packageName": "MediaAgent"
}
],
},
"entities": [
{
"clientId": 0,
}
]
}
EOF
)
shopt -u nocasematch #Sets options back to being case sensitive
echo "$csName"
curl -vv --location --request POST "http://$csName:81/SearchSvc/CVWebService.svc/InstallClient" --header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header "Authtoken: $token" \
-d "$curlData"
Doing a bash -x everything looks correct
"rebootClient": false,
"createPseudoClientRequest": {
"registerClient": true,
"clientInfo": {
"clientType": 0,
}
},
"packages": [
{
"packageId": 702,
"packageName": "File System",
"packageId": 51,
"packageName": "MediaAgent"
}
],
"clientAuthForJob": {
},
"entities": [
{
"clientId": 0,
"clientName": "srybrcost",
}
]
}'
But every time I get Request body is empty or format is invalid

Classroom Orphaned by deleted teacher account

My predecessor was in the habit of deleting users from gsuite. This has resulted in 18 courses that I cannot figure out how to change from ACTIVE to ARCHIVED.
GET https://classroom.googleapis.com/v1/courses/#######?key=[YOUR_API_KEY] HTTP/1.1
{
"id": "#######",
"name": "Course Name",
"ownerId": "#####################",
"creationTime": "2014-01-01T00:00:00.000Z",
"updateTime": "2015-01-01T00:00:00.000Z",
"enrollmentCode": "xx#xxx#",
"courseState": "ACTIVE",
"alternateLink": "https://classroom.google.com/c/XXX#XXXxXxxx",
"teacherGroupEmail": "Course_Name_teachers_#xXxXx#domain.com",
"courseGroupEmail": "Course_Name--#xXxXx#comain.com",
"teacherFolder": {
"id": "#X#Xx#xxX#xXXxXXXX#xXxXXxxXx"
},
"guardiansEnabled": false
}
Trying to PATCH the class to ARCHIVED:
curl --request PATCH \
'https://classroom.googleapis.com/v1/courses/#######?updateMask=courseState&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"courseState":"ARCHIVED"}' \
--compressed
Returns error 500:
{
"error": {
"code": 500,
"message": "Internal error encountered.",
"status": "INTERNAL"
}
}
It's a bug that Google seems to be aware of and has no solution at this time.
https://issuetracker.google.com/issues/36760244#comment13

Does parse.com support batch operations for push notifications?

I am attempting to do a batch push notification request using the parse rest API.
curl -X POST
-H "X-Parse-Application-Id: redacted"
-H "X-Parse-REST-API-Key: redacted"
-H "Content-Type: application/json"
-d '{
"requests": [{
"method": "POST",
"path": "/1/push/",
"body": {
"channels": ["redacted"],
"deviceType": "ios",
"badge": 1,
"data": {
"alert": "Hello",
"badge": 1,
"key": "status"
}
}
}]
https://api.parse.com/1/batch
And am receiving the error:
{"code":107,"error":"Method 'POST' to '/1/push/' not supported in batch operations."}
You are already indicating POST in CURL. The Parse push api is not batch. Push is sent to registered devices in Parse (associated with a certificate from Apple) and those matching your push criteria. Your push message should look more like this:
curl -X POST \
-H "X-Parse-Application-Id: " \
-H "X-Parse-REST-API-Key: " \
-H "Content-Type: application/json" \
-d '{
"where": {
"channels": {
"$in": ["channel1","channel2","channel3"]
},
"deviceType": "ios"
},
"data": {
"alert": "Alert message here."
}
}' \
https://api.parse.com/1/push
There are various examples in the docs. The above is from the help forum.

Resources