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.
Related
I'm trying to reset the lock code of my device through android management API but it seems that RESET_PASSWORD doesn't do anything. The endpoint is https://androidmanagement.googleapis.com/v1/enterprises/entrepriseID/devices/deviceID:issueCommand and my payload looks like this
{
"type": "RESET_PASSWORD" ,
"duration": "600s",
"newPassword":"1234",
"resetPasswordFlags":["LOCK_NOW"]
}
Does anyone find any solution ?
I have the same problem with this command :
I find the command in the documentation.
When i execute this CURL, it answer me 200 OK.
curl --location --request POST 'https://androidmanagement.googleapis.com/v1/enterprises/<enterprise>/devices/<device_id>:issueCommand' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer <TOKEN>' \
--data-raw '{
"type": "RESET_PASSWORD",
"duration": "600s"
}'
{
"name": "enterprises/<enterprise>/devices/<device_id>/operations/<operation_id>",
"metadata": {
"#type": "type.googleapis.com/google.android.devicemanagement.v1.Command",
"type": "RESET_PASSWORD",
"createTime": "2022-05-03T09:34:15.913Z",
"duration": "600s",
"userName": "enterprises/<enterprise>/users/<user_id>"
}
}
But, when i try to get the health of the operation, it answer to me an error:
curl --location --request GET 'https://androidmanagement.googleapis.com/v1/enterprises/<enterprise>/devices/<device_id>/operations/<operation_id>' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer <TOKEN>'
Answer (200 OK):
{
"name": "enterprises/<enterprise>/devices/<device_id>/operations/<operation_id>",
"metadata": {
"#type": "type.googleapis.com/google.android.devicemanagement.v1.Command",
"type": "RESET_PASSWORD",
"createTime": "2022-05-03T09:34:15.913Z",
"duration": "600s",
"errorCode": "INVALID_VALUE",
"userName": "enterprises/<enterprise>/users/<user_id>"
},
"done": true,
"error": {
"code": 3
}
}
i don't know which invalid value i put into the params..
More, the LOCK or REBOOT command work correctly without any error for the same device.
Sincerely.
Adrien.
I tried to recreate the scenario using the same settings that you are using and I was able to reset my password and change it to the new password.
device_name = enterprise_name + '/devices/deviceId'
device_json = '''
{
"duration": "600s",
"type": "RESET_PASSWORD",
"newPassword": "12345",
"resetPasswordFlags": [
"LOCK_NOW"
]
}
'''
androidmanagement.enterprises().devices().issueCommand(
name=device_name,
body=json.loads(device_json)
).execute()
This API seems to be working properly in my end. For this API to work properly, please make sure the newPassword value meets any passwordRequirements you have set in the policy. Also, you can check the device if it receives the command as it should lock its screen automatically upon receiving the command.
You can also try using other commands to ensure that the issue is not in your device or connection.
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)
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
I know I can use html and markdown in my incoming webhook, but when I try to embed a link, it does not work. Need help, please
curl -H "Content-Type: application/json" -d "{\"text\": \"<a href=' www.microsoft.com'>visit</a >\"}" <my webhook url>
curl -H "Content-Type: application/json" -d "{\"text\": \"[visit](www.microsoft.com)\"}" <my webhook url>
Standard markdown can be used:
curl --header "Content-Type: application/json" \
--data "{\"text\": \"[visit](https://www.microsoft.com)\"}" \
<my webhook url>
Note that OP omitted the URI scheme, which prevents Teams from identifying the URL as a valid one.
I got the similar issue before, and I found I could use adaptive cards. It's much more powerful! Below is the sample payload.
{
"#type": "MessageCard",
"#context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "a summary",
"sections": [{
"activityTitle": "A title",
"activitySubtitle": "a subtitle",
"markdown": true
}],
"potentialAction": [{
"#type": "ActionCard",
"name": "Visit",
"actions": [{
"#type": "OpenUri",
"name": "Visit",
"targets": [
{ "os": "default", "uri": "https://www.microsoft.com" }
]
}]
}]
}
I try to perform an update with ajax on my db but it's not working.
Url i tried :
http://localhost:8880/api/Tracks/update?filter{"id ": "1"}
What i get :
{
"error": {
"name": "AssertionError",
"status": 500,
"message": "The where argument must be an object",
"actual": false,
"expected": true,
"operator": "==",
"generatedMessage": false,
}
}
Thanks !
Try for this:
curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" -d "{
//your data here
}" "http://localhost:aaaa/xx/yy/%7B%22id%22%3A1%7D"