Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with the Play Framework
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Add-ons
  • All Add-ons
  • Pushwoosh
Pushwoosh

This add-on is operated by Pushwoosh, Inc

Fast & Smart Push Notification Service

Pushwoosh

Last updated October 09, 2019

The Pushwoosh add-on is currently in beta.

Table of Contents

  • Provisioning the add-on
  • Client side integration
  • Sending API requests
  • Use with Ruby
  • Use with PHP
  • Use with Python
  • Use with Java
  • Use with Golang
  • Dashboard
  • Removing the add-on
  • Support

Pushwoosh is a real-time cross-platform push notification service. The Pushwoosh add-on allows you to engage your audience effectively by sending unlimited push notifications to websites and mobile apps.

Provisioning the add-on

Pushwoosh can be attached to a Heroku application via the CLI:

A list of all plans available can be found here.

$ heroku addons:create pushwoosh

In order to apply the add-on to your Heroku app you need to link your credit card to your Heroku account.

Once the add-on has been attached to your app, the Pushwoosh account will be automatically created for you. The account allows you to send unlimited pushes and use API access. The API token will be created and saved in the PUSHWOOSH_API_TOKEN config var.

Once the Pushwoosh account has been created, your application will be automatically added to the Pushwoosh control panel. The application code will be created and saved in the PUSHWOOSH_APPLICATION_CODE config var.

The configuration variable PUSHWOOSH_API_TOKEN can be confirmed using the heroku config:get command.

$ heroku config:get PUSHWOOSH_API_TOKEN

Client side integration

Our SDKs allow you to seamlessly integrate the Pushwoosh service into your app or your website regardless of the platform you’re using.

Platform How to integrate
iOS iOS Configuration
Android FCM Integration
OS X Mac OS X Push Notification SDK
CHROME Chrome Web Push
SAFARI [https://www.pushwoosh.com/v1.0/docs/safari-website-notifications)
Other See Pushwoosh Docs

Sending API requests

Use /createMessage to send requests via the Pushwoosh API. Replace API_TOKEN with one of the following code samples, depending on the programming language you use.

Ruby

ENV['PUSHWOOSH_API_TOKEN']

PHP

$_ENV['PUSHWOOSH_API_TOKEN']

Python

os.environ['PUSHWOOSH_API_TOKEN']

Java

System.getenv("PUSHWOOHS_API_TOKEN")

Golang

os.Getenv("PUSHWOOSH_API_TOKEN")

Use with Ruby

class PushNotification

  #- PushWoosh API Documentation http://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/
  #- Two methods here:
  #     - PushNotification.new.notify_all(message) Notifies all with the same option
  #     - PushNotification.new.notify_devices(notification_options = {}) Notifies specific devices with custom options

  include HTTParty #Make sure to have the HTTParty gem declared in your gemfile https://github.com/jnunemaker/httparty
  default_params :output => 'json'
  format :json

  def initialize
    #- Change to your settings
    @auth = {:application  => "00000-00000",:auth => ENV['PUSHWOOSH_API_TOKEN']}
  end

  # PushNotification.new.notify_all("This is a test notification to all devices")
  def notify_all(message)
    notify_devices({:content  => message})
  end

  # PushNotification.new.notify_device({
  #  :content  => "TEST",
  #  :data  => {:custom_data  => value},
  #  :devices  => array_of_tokens
  #})
  def notify_devices(notification_options = {})
    #- Default options, uncomment :data or :devices if needed
    default_notification_options = {
                        # YYYY-MM-DD HH:mm  OR 'now'
                        :send_date  => "now",
                        # Object( language1: 'content1', language2: 'content2' ) OR string
                        :content  => {
                            :fr  => "Test",
                            :en  => "Test"
                        },
                        # JSON string or JSON object "custom": "json data"
                        #:data  => {
                        #    :custom_data  => value
                        #},
                        # omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs
                        #:devices  => {}
                      }

    #- Merging with specific options
    final_notification_options = default_notification_options.merge(notification_options)

    #- Constructing the final call
    options = @auth.merge({:notifications  => [final_notification_options]})
    options = {:request  => options}
    #- Executing the POST API Call with HTTPARTY - :body => options.to_json allows us to send the json as an object instead of a string
    response = self.class.post("https://cp.pushwoosh.com/json/1.3/createMessage", :body  => options.to_json,:headers => { 'Content-Type' => 'application/json' })
  end
end

Use with PHP

<?php
define('PW_APPLICATION', 'APPLICATION CODE');
define('PW_DEBUG', true);

function pwCall($method, $data) {
    $url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
    $request = json_encode(['request' => $data]);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    if (defined('PW_DEBUG') && PW_DEBUG) {
        print "[PW] request: $request\n";
        print "[PW] response: $response\n";
        print "[PW] info: " . print_r($info, true);
    }
}

pwCall('createMessage', array(
    'application' => PW_APPLICATION,
    'auth' => $_ENV['PUSHWOOSH_API_TOKEN'],
    'notifications' => array(
            array(
                'send_date' => 'now',
                'content' => 'test',
                'data' => array('custom' => 'json data'),
                'link' => 'http://pushwoosh.com/'
            )
        )
    )
);

Use with Python

import json

PW_AUTH = os.environ['PUSHWOOSH_API_TOKEN']
PW_APPLICATION_CODE = 'APPLICATION CODE'

try:
    # For Python 3.0 and later
    from urllib.request import urlopen
    from urllib.request import Request
except ImportError:
    # Fall back to Python 2's urllib2
    from urllib2 import urlopen
    from urllib2 import Request

def pw_call(method, data):
    url = 'https://cp.pushwoosh.com/json/1.3/' + method
    data = json.dumps({'request': data})
    req = Request(url, data.encode('UTF-8'), {'Content-Type': 'application/json'})
    try:
        f = urlopen(req)
        response = f.read()
        f.close()
        print('Pushwoosh response: ' + str(response))
    except Exception as e:
        print ('Request error: ' + str(e))

if __name__ == '__main__':
    pw_call('createMessage', {
        'auth': PW_AUTH,
        'application': PW_APPLICATION_CODE,
        'notifications': [
            {
                'send_date': 'now',
                'content': 'test',
                'data': {"custom": "json data"},
                'link': 'http://pushwoosh.com'
            }
        ]
    }
    )

Use with Java

// Uses JSON classes from http://json.org/java/

package com.pushwoosh;

import org.json.*;
import java.io.*;
import java.net.*;

public class SendPushNotificationSample
{
    public static final String PUSHWOOSH_SERVICE_BASE_URL = "https://cp.pushwoosh.com/json/1.3/";
    private static final String APPLICATION_CODE = "PW_APPLICATION_CODE";

    public static void main(String[] args) throws JSONException, MalformedURLException
    {
        String method = "createMessage";
        URL url = new URL(PUSHWOOSH_SERVICE_BASE_URL + method);

        JSONArray notificationsArray = new JSONArray()
                .put(new JSONObject().put("send_date", "now")
                                     .put("content", "test")
                                     .put("link", "http://pushwoosh.com/"));

        JSONObject requestObject = new JSONObject()
                .put("application", APPLICATION_CODE)
                .put("auth", System.getenv("PUSHWOOHS_API_TOKEN"))
                .put("notifications", notificationsArray);

        JSONObject mainRequest = new JSONObject().put("request", requestObject);
        JSONObject response = SendServerRequest.sendJSONRequest(url, mainRequest.toString());

        System.out.println("Response is: " + response);
    }
}

class SendServerRequest
{
    static JSONObject sendJSONRequest(URL url, String request)
    {
        HttpURLConnection connection = null;
        try
        {
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setDoInput(true);
            connection.setDoOutput(true);

            DataOutputStream writer = new DataOutputStream(connection.getOutputStream());
            writer.write(request.getBytes("UTF-8"));
            writer.flush();
            writer.close();

            return parseResponse(connection);
        }
        catch (Exception e)
        {
            System.out.println("An error occurred: " + e.getMessage());
            return null;
        }
        finally
        {
            if (connection != null)
            {
                connection.disconnect();
            }
        }
    }

    static JSONObject parseResponse(HttpURLConnection connection) throws IOException, JSONException
    {
        String line;
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        StringBuilder response = new StringBuilder();

        while ((line = reader.readLine()) != null)
        {
            response.append(line).append('\r');
        }
        reader.close();

        return new JSONObject(response.toString());
    }
}

Use with Golang

package main

import
(
  "fmt"
  "encoding/json"
  "net/http"
  "bytes"
  "io/ioutil"
)

const (
  PW_APPLICATION = "APPLICATION CODE"
  PW_ENDPOINT = "https://cp.pushwoosh.com/json/1.3/"
)

func pwCall(method string, data []byte) (bool) {
  url := PW_ENDPOINT + method
  request, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
  request.Header.Set("Content-Type", "application/json")

  client := http.Client{}
  response, err := client.Do(request)
  if err != nil {
    fmt.Println("Error occur: " + err.Error())
    return false
  }
  defer response.Body.Close()

  fmt.Println("Response Status: ", response.Status)
  if (response.StatusCode == 200) {
    body, _ := ioutil.ReadAll(response.Body)
    fmt.Println("Response Body: ", string(body))
    return true
  }
  return false
}

func main() {
  requestData := map[string]interface{}{
    "request": map[string]interface{} {
      "auth": os.Getenv("PUSHWOOSH_API_TOKEN"),
      "application": PW_APPLICATION,
      "notifications": []interface{}{
        map[string]interface{} {
          "send_date": "now",
          "content": "test",
          "link": "https://pushwoosh.com",
        },
      },
    },
  }
  jsonRequest, _ := json.Marshal(requestData)
  requestString := string(jsonRequest)
  fmt.Println("Request body: " + requestString)

  pwCall("createMessage", jsonRequest)
}

Dashboard

Pushwoosh Dashboard allows you to add and configure applications depending on your needs and can be accessed via the CLI:

$ heroku addons:open pushwoosh

or by visiting the Heroku Dashboard and selecting your Heroku application where you have the Pushwoosh add-on installed.

Removing the add-on

The Pushwoosh add-on can be removed via the CLI.

This will destroy all associated data. You will have 7 days for a backup.

$ heroku addons:destroy pushwoosh

Or you can select the Remove option in Heroku Dashboard

Removing add-on

Support

All Pushwoosh support issues should be submitted via one of the Heroku Support channels. Any non-support related issues or product feedback are welcome at help@pushwoosh.com or via Twitter @Pushwoosh.

Keep reading

  • All Add-ons

Feedback

Log in to submit feedback.

Ziggeo QRackajack

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences