[GH-ISSUE #1060] Documentation for Using Tokens via PowerShell Appears to be Incorrect #743

Closed
opened 2026-05-07 00:27:06 +02:00 by BreizhHardware · 3 comments

Originally created by @theparadox1083 on GitHub (Mar 20, 2024).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1060

🐞 Describe the bug
In the documentation here: https://docs.ntfy.sh/publish/#access-tokens
The PowerShell 7+ example is

# With PowerShell 7 or greater, we can use the Authentication and Token parameters
$Request = @{
  Method = "POST"
  URI = "https://ntfy.example.com/mysecrets"
  Authorization = "Bearer"
  Token = "tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2"
  Body = "Look ma, with auth"
}
Invoke-RestMethod @Request

I tried this out and encountered two problems using Invoke-RestMethod as used in the example in the ntfy documentation.

  1. The parameter Authorization should be Authentication - your comment mentions the correct parameter but the example uses the a parameter that doesn't exist.
  2. PowerShell requires the token be a SecureString

Understandably, the second issue might require some explanation for anyone not familiar with PowerShell but the code below technically works. Ideally you'd want to import a SecureString from a file or vault or something but I don't see any other token examples make an effort to keep the token secret so I didn't bother with that in my recommended correction - I just convert on the fly which is absolutely not recommended.

# With PowerShell 7 or greater, we can use the Authentication and Token parameters
# The Token parameter must be in the form of a System.Security.SecureString

$Request = @{
  Method = "POST"
  URI = "https://ntfy.example.com/mysecrets"
  Authentication = "Bearer"
  Token = ConvertTo-SecureString "tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2" -AsPlainText
  Body = "Look ma, with auth"
}
Invoke-RestMethod @Request

💻 Components impacted
Documentation regarding Access Tokens and PowerShell 7+

💡 Screenshots and/or logs

Re 1:

|
|  Invoke-RestMethod @Request
|                    ~~~~~~~~
| A parameter cannot be found that matches parameter name 'Authorization'.

Re 2:

|
|  Invoke-RestMethod @Request
|                    ~~~~~~~~
| Cannot bind parameter 'Token'. Cannot convert the value of type "System.String" to type "System.Security.SecureString".

🔮 Additional context

Originally created by @theparadox1083 on GitHub (Mar 20, 2024). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1060 :lady_beetle: **Describe the bug** In the documentation here: [https://docs.ntfy.sh/publish/#access-tokens](https://docs.ntfy.sh/publish/#access-tokens) The PowerShell 7+ example is ```PowerShell # With PowerShell 7 or greater, we can use the Authentication and Token parameters $Request = @{ Method = "POST" URI = "https://ntfy.example.com/mysecrets" Authorization = "Bearer" Token = "tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2" Body = "Look ma, with auth" } Invoke-RestMethod @Request ``` I tried this out and encountered two problems using [Invoke-RestMethod](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.4) as used in the [example](https://docs.ntfy.sh/publish/#access-tokens) in the ntfy documentation. 1. The parameter `Authorization` should be `Authentication` - your comment mentions the correct parameter but the example uses the a parameter that doesn't exist. 2. PowerShell requires the token be a [SecureString](https://learn.microsoft.com/en-us/dotnet/api/system.security.securestring?view=net-8.0) Understandably, the second issue might require some explanation for anyone not familiar with PowerShell but the code below technically works. Ideally you'd want to import a SecureString from a file or vault or something but I don't see any other token examples make an effort to keep the token secret so I didn't bother with that in my recommended correction - I just convert on the fly which is absolutely not recommended. ```PowerShell # With PowerShell 7 or greater, we can use the Authentication and Token parameters # The Token parameter must be in the form of a System.Security.SecureString $Request = @{ Method = "POST" URI = "https://ntfy.example.com/mysecrets" Authentication = "Bearer" Token = ConvertTo-SecureString "tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2" -AsPlainText Body = "Look ma, with auth" } Invoke-RestMethod @Request ``` :computer: **Components impacted** Documentation regarding Access Tokens and PowerShell 7+ :bulb: **Screenshots and/or logs** Re 1: ``` | | Invoke-RestMethod @Request | ~~~~~~~~ | A parameter cannot be found that matches parameter name 'Authorization'. ``` Re 2: ``` | | Invoke-RestMethod @Request | ~~~~~~~~ | Cannot bind parameter 'Token'. Cannot convert the value of type "System.String" to type "System.Security.SecureString". ``` :crystal_ball: **Additional context**
BreizhHardware 2026-05-07 00:27:06 +02:00
  • closed this issue
  • added the
    🪲 bug
    label
Author
Owner

@binwiederhier commented on GitHub (Mar 21, 2024):

All the PowerShell stuff is contributed by other people, so I do not know what is best practice or works. WOuld you be able to create a pull request with your suggestions?

<!-- gh-comment-id:2011045188 --> @binwiederhier commented on GitHub (Mar 21, 2024): All the PowerShell stuff is contributed by other people, so I do not know what is best practice or works. WOuld you be able to create a pull request with your suggestions?
Author
Owner

@theparadox1083 commented on GitHub (Mar 21, 2024):

Done - I just created my first PR ever! Hopefully I did it correctly?

<!-- gh-comment-id:2012339316 --> @theparadox1083 commented on GitHub (Mar 21, 2024): Done - I just created my first PR ever! Hopefully I did it correctly?
Author
Owner

@binwiederhier commented on GitHub (Mar 25, 2024):

Congrats on your first-ever PR. You did everything right. Thank you for your contribution!

<!-- gh-comment-id:2018017949 --> @binwiederhier commented on GitHub (Mar 25, 2024): Congrats on your first-ever PR. You did everything right. Thank you for your contribution!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#743
No description provided.