Example code and Pushover libraries
Pushover's API is designed to be easy to use without the overhead of complicated authentication mechanisms like OAuth. For full details on our API endpoints, see our API Documentation.
To quickly get started sending Pushover messages with a wide variety of programming languages, we have some sample code as well as a number of 3rd party libraries written and maintained by Pushover users.
In all of these examples, replace USER_KEY with your Pushover User Key (which can be found on your dashboard) or that of the user/group to which you are sending, and API_TOKEN with your application's API Token. If you don't already have an application API Token, you can create one for free.
Note: if your language of choice is not listed here, try browsing all GitHub libraries tagged "pushover".
C
The 3rd party cpushover
library written by Christian Bjartli is available. This library uses libcurl.
C#/.NET
Using the built-in HttpClient class:
var parameters = new Dictionary<string, string> {
["token"] = "APP_TOKEN",
["user"] = "USER_KEY",
["message"] = "hello world"
};
using var client = new HttpClient();
var response = await client.PostAsync("https://api.pushover.net/1/messages.json", new
FormUrlEncodedContent(parameters));
Alternatively, the 3rd party Pushover.NET
package written by Matthew Sawyer, and the Pushover-API
package written by Michal Altair Valášek are available.
C++ / ESP32
The 3rd party PushoverESP32
library written by Bruno Joyal is available.
Go
The 3rd party gopush
package written by Kyle Isom is available, as well as the pushover
package written by Grégoire Delattre.
Haskell
The 3rd party hPushover
package written by Wander Hillen is available.
Java
The 3rd party pushover4j
package written by Sean Scanlon is available.
The 3rd party Pushover API Micronaut Java library written by Sergio del Amo is also available.
Lua
The 3rd party pushover-lua
package written by Sven Andersson is available.
Node
The 3rd party node-pushover
package written by Sam Decrock, the pushover-notifications
package written by Aaron Bieber, and the chump
package written by Michael Squires are all available via npm.
Perl
Using the CPAN module LWP::UserAgent
may also require the Mozilla::CA
module installed for proper TLS validation:
use LWP::UserAgent; LWP::UserAgent->new()->post( "https://api.pushover.net/1/messages.json", [ "token" => "APP_TOKEN", "user" => "USER_KEY", "message" => "hello world", ]);
Alternatively, the 3rd party WebService::Pushover
Perl module written by Steve Huff is available in CPAN.
PHP
Using the built-in cURL module:
<?php curl_setopt_array($ch = curl_init(), array( CURLOPT_URL => "https://api.pushover.net/1/messages.json", CURLOPT_POSTFIELDS => array( "token" => "APP_TOKEN", "user" => "USER_KEY", "message" => "hello world", ), CURLOPT_SAFE_UPLOAD => true, CURLOPT_RETURNTRANSFER => true, )); curl_exec($ch); curl_close($ch); ?>
Alternatively, there are a number of 3rd party PHP libraries available:
php-pushover
PHP class written by Chris SchalenborghPushy
PHP package written by Michael SquiresPushover for PHP
package written by Leonardo C. TeixeiraLaravel-pushover
package for the Laravel framework written by Dyaa Eldin Moustafalaravel-pushover
package for the Laravel framework written by Edward Karlssoncodeigniter4-pushover
package for the CodeIgniter 4 framework written by Tatter Softwarepushover-php
package written by Serhiy Lunak
PHP with Image Attachment
Please see our API documentation for information about attachments such as file size limits.
The cURL module can be used, though the curl_file_create function requires at least PHP 5.5.
<?php curl_setopt_array($ch = curl_init(), array( CURLOPT_URL => "https://api.pushover.net/1/messages.json", CURLOPT_POSTFIELDS => array( "token" => "APP_TOKEN", "user" => "USER_KEY", "message" => "hello world", "attachment" => curl_file_create("image.jpg", "image/jpeg"), ), CURLOPT_SAFE_UPLOAD => true, CURLOPT_RETURNTRANSFER => true, )); curl_exec($ch); curl_close($ch); ?>
Python
The standard httplib
and urllib
libraries can be used:
import httplib, urllib conn = httplib.HTTPSConnection("api.pushover.net:443") conn.request("POST", "/1/messages.json", urllib.urlencode({ "token": "APP_TOKEN", "user": "USER_KEY", "message": "hello world", }), { "Content-type": "application/x-www-form-urlencoded" }) conn.getresponse()
For Python 3, httplib
has been replaced with http.client
and urlencode
has moved to urllib.parse
.
import http.client, urllib conn = http.client.HTTPSConnection("api.pushover.net:443") conn.request("POST", "/1/messages.json", urllib.parse.urlencode({ "token": "APP_TOKEN", "user": "USER_KEY", "message": "hello world", }), { "Content-type": "application/x-www-form-urlencoded" }) conn.getresponse()
Alternatively, a number of 3rd party packages are available: pushnotify
package written by Jeffrey Goettsch, pushover
Python 3 package written by Wyatt Johnson, Chump
Python package written by Karan Lyons, and python-pushover
Python package written by Thibaut Horel.
Python with Image Attachment
To send an image attachment, the 3rd party Requests library can be used. For example, to send the file "your_image.jpg
":
import requests r = requests.post("https://api.pushover.net/1/messages.json", data = { "token": "APP_TOKEN", "user": "USER_KEY", "message": "hello world" }, files = { "attachment": ("image.jpg", open("your_image.jpg", "rb"), "image/jpeg") }) print(r.text)
R
The 3rd party pushoverr
R module written by Brian Connelly is available.
Ruby
The standard Net::HTTPS
library can be used:
require "net/https" url = URI.parse("https://api.pushover.net/1/messages.json") req = Net::HTTP::Post.new(url.path) req.set_form_data({ :token => "APP_TOKEN", :user => "USER_KEY", :message => "hello world", }) res = Net::HTTP.new(url.host, url.port) res.use_ssl = true res.verify_mode = OpenSSL::SSL::VERIFY_PEER res.start {|http| http.request(req) }
Alternatively, the 3rd party rushover
Ruby module written by Brendon Murphy is available through Ruby Gems.
Rust
The 3rd party po
Rust library written by Jordan Mulcahey is available.
Swift
The 3rd party pushover
Swift library written by Kilian Koeltzsch is available.
Visual Basic for Applications (VBA)
The 3rd party pushover-vba
module written by Mauricio Arieira is available.
Unix command line
The curl
program may be used from the command line or integrated into shell scripts:
curl -s \ --form-string "token=APP_TOKEN" \ --form-string "user=USER_KEY" \ --form-string "message=hello world" \ https://api.pushover.net/1/messages.json
Unix command line with Image Attachment
Please see our API documentation for information about attachments such as file size limits.
curl
can easily upload files as parameters by specifying a parameter such as "attachment=@filename.jpg
" as the value, which will read filename.jpg
on your computer and send it as the attachment
parameter, complete with the necessary meta-data such as its Content-Type
and name
.
Note: because curl does file uploading automatically with the -F
option, we strongly recommend using --form-string
for all other parameters to avoid being tricked into sending a file from your computer as parameter data if you are passing message data from external sources.
curl -s \ --form-string "token=APP_TOKEN" \ --form-string "user=USER_KEY" \ --form-string "message=here is an image attachment" \ -F "attachment=@image.jpg" \ https://api.pushover.net/1/messages.json
Windows command line
The curl
program may be used (Download a Win32 build with TLS support):
curl -s \ --cacert curl-ca-bundle.crt \ --form-string "token=APP_TOKEN" \ --form-string "user=USER_KEY" \ --form-string "message=hello world" \ https://api.pushover.net/1/messages.json
Alternatively, PowerShell can be used. For PowerShell v3, using the new Invoke-RestMethod cmdlet, courtesy of Hal Rottenberg:
$uri = "https://api.pushover.net/1/messages.json" $parameters = @{ token = "APP_TOKEN" user = "USER_KEY" message = "hello world" } $parameters | Invoke-RestMethod -Uri $uri -Method Post
Or for older versions:
$parameters = New-Object System.Collections.Specialized.NameValueCollection $parameters.Add("token", "APP_TOKEN") $parameters.Add("user", "USER_KEY") $parameters.Add("message", "hello world") $client = New-Object System.Net.WebClient $client.UploadValues("https://api.pushover.net/1/messages.json", $parameters)
The 3rd party PowerShell modules PowerShellPushOver written by Kieran Jacobsen, and PushoverForPS written by Chris Carter are also available.