Merge pull request #345 from noahpeltier/fix-powershell-docs
Updated syntax on PowerShell examples in docspull/348/head
commit
50a830c360
|
@ -885,15 +885,21 @@ is the only required one:
|
||||||
``` 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 = @(
|
||||||
|
@{
|
||||||
|
action = "view"
|
||||||
|
label = "Admin panel"
|
||||||
|
url = "https://filesrv.lan/admin"
|
||||||
|
}
|
||||||
|
)
|
||||||
} | 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
|
||||||
```
|
```
|
||||||
|
@ -1210,20 +1216,20 @@ 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
|
||||||
|
@ -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 returned 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 returned 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 New Issue