Updated powershell examples to correct syntax
This commit is contained in:
parent
30c8d6b02b
commit
eb841604c7
1 changed files with 58 additions and 49 deletions
107
docs/publish.md
107
docs/publish.md
|
@ -883,19 +883,25 @@ is the only required one:
|
||||||
|
|
||||||
=== "PowerShell"
|
=== "PowerShell"
|
||||||
``` powershell
|
``` powershell
|
||||||
$uri = "https://ntfy.sh"
|
$uri = "https://ntfy.sh"
|
||||||
$body = @{
|
$body = @{
|
||||||
"topic"="powershell"
|
topic = "powershell"
|
||||||
"title"="Low disk space alert"
|
title = "Low disk space alert"
|
||||||
"message"="Disk space is low at 5.1 GB"
|
message = "Disk space is low at 5.1 GB"
|
||||||
"priority"=4
|
priority = 4
|
||||||
"attach"="https://filesrv.lan/space.jpg"
|
attach = "https://filesrv.lan/space.jpg"
|
||||||
"filename"="diskspace.jpg"
|
filename = "diskspace.jpg"
|
||||||
"tags"=@("warning","cd")
|
tags = @("warning", "cd")
|
||||||
"click"= "https://homecamera.lan/xasds1h2xsSsa/"
|
click = "https://homecamera.lan/xasds1h2xsSsa/"
|
||||||
"actions"=@[@{ "action"="view", "label"="Admin panel", "url"="https://filesrv.lan/admin" }]
|
actions = @(
|
||||||
} | ConvertTo-Json
|
@{
|
||||||
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
action = "view"
|
||||||
|
label = "Admin panel"
|
||||||
|
url = "https://filesrv.lan/admin"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} | ConvertTo-Json
|
||||||
|
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
@ -1210,24 +1216,24 @@ Alternatively, the same actions can be defined as **JSON array**, if the notific
|
||||||
``` powershell
|
``` powershell
|
||||||
$uri = "https://ntfy.sh"
|
$uri = "https://ntfy.sh"
|
||||||
$body = @{
|
$body = @{
|
||||||
"topic"="myhome"
|
topic = "myhome"
|
||||||
"message"="You left the house. Turn down the A/C?"
|
message = "You left the house. Turn down the A/C?"
|
||||||
"actions"=@(
|
actions = @(
|
||||||
@{
|
@{
|
||||||
"action"="view"
|
action = "view"
|
||||||
"label"="Open portal"
|
label = "Open portal"
|
||||||
"url"="https://home.nest.com/"
|
url = "https://home.nest.com/"
|
||||||
"clear"=true
|
clear = $true
|
||||||
},
|
},
|
||||||
@{
|
@{
|
||||||
"action"="http",
|
action = "http"
|
||||||
"label"="Turn down"
|
label = "Turn down"
|
||||||
"url"="https://api.nest.com/"
|
url = "https://api.nest.com/"
|
||||||
"body"="{\"temperature\": 65}"
|
body = '{"temperature": 65}'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} | ConvertTo-Json
|
} | ConvertTo-Json
|
||||||
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
@ -1470,9 +1476,9 @@ And the same example using [JSON publishing](#publish-as-json):
|
||||||
``` powershell
|
``` powershell
|
||||||
$uri = "https://ntfy.sh"
|
$uri = "https://ntfy.sh"
|
||||||
$body = @{
|
$body = @{
|
||||||
"topic"="myhome"
|
topic = "myhome"
|
||||||
"message"="Somebody retweetet your tweet."
|
message = "Somebody retweetet your tweet."
|
||||||
"actions"=@(
|
actions = @(
|
||||||
@{
|
@{
|
||||||
"action"="view"
|
"action"="view"
|
||||||
"label"="Open Twitter"
|
"label"="Open Twitter"
|
||||||
|
@ -1727,19 +1733,22 @@ And the same example using [JSON publishing](#publish-as-json):
|
||||||
``` powershell
|
``` powershell
|
||||||
$uri = "https://ntfy.sh"
|
$uri = "https://ntfy.sh"
|
||||||
$body = @{
|
$body = @{
|
||||||
"topic"="wifey"
|
topic = "wifey"
|
||||||
"message"="Your wife requested you send a picture of yourself."
|
message = "Your wife requested you send a picture of yourself."
|
||||||
"actions"=@(
|
actions = @(
|
||||||
@{
|
@{
|
||||||
"action"="broadcast"
|
action = "broadcast"
|
||||||
"label"="Take picture"
|
label = "Take picture"
|
||||||
"extras"=@{
|
extras = @{
|
||||||
"cmd"="pic"
|
cmd ="pic"
|
||||||
"camera"="front"
|
camera = "front"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} | ConvertTo-Json
|
|
||||||
|
# Powershell requires the 'Depth' argument to equal 3 here to expand 'Extras', otherwise it will read System.Collections.Hashtable in the resturned json
|
||||||
|
|
||||||
|
} | ConvertTo-Json -Depth 3
|
||||||
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1995,22 +2004,22 @@ And the same example using [JSON publishing](#publish-as-json):
|
||||||
``` powershell
|
``` powershell
|
||||||
$uri = "https://ntfy.sh"
|
$uri = "https://ntfy.sh"
|
||||||
$body = @{
|
$body = @{
|
||||||
"topic"="myhome"
|
topic = "myhome"
|
||||||
"message"="Garage door has been open for 15 minutes. Close it?"
|
message = "Garage door has been open for 15 minutes. Close it?"
|
||||||
"actions"=@(
|
actions = @(
|
||||||
@{
|
@{
|
||||||
"action"="http",
|
action = "http"
|
||||||
"label"="Close door"
|
label = "Close door"
|
||||||
"url"="https://api.mygarage.lan/"
|
url = "https://api.mygarage.lan/"
|
||||||
"method"="PUT"
|
method = "PUT"
|
||||||
"headers"=@{
|
headers = @{
|
||||||
"Authorization"="Bearer zAzsx1sk.."
|
Authorization = "Bearer zAzsx1sk.."
|
||||||
}
|
}
|
||||||
"body"="{\"action\": \"close\"}"
|
body = '{"action": "close"}'
|
||||||
}
|
}
|
||||||
}
|
|
||||||
)
|
)
|
||||||
} | ConvertTo-Json
|
# Powershell requires the 'Depth' argument to equal 3 here to expand 'headers', otherwise it will read System.Collections.Hashtable in the resturned json
|
||||||
|
} | ConvertTo-Json -Depth 3
|
||||||
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
Invoke-RestMethod -Method 'Post' -Uri $uri -Body $body -ContentType "application/json" -UseBasicParsing
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue