Installation guides

Choose your platform

PHP

Install the PHP library using Composer:

composer require stackmash/stackmash-php

Use the Stackmash namespace:

use Stackmash\Stackmash;

Get the project you want to send notification to using your project keys:

$project = Stackmash::getProject("YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY");

Create a notification:

$project->action('general', 'You have a new notification', ["Hello" => "Stackmash!"]);
Configuration options

By default, the browser, OS and IP address of the users is not sent to the servers. If you would like to enable this, you can parse configuration settings to the project using the following example:

$project = Stackmash::getProject("YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY", $config);

The config settings can be defined like this, setting true of false depending on what you would like to send to the Stackmash servers:

$config = ['showBrowser' => false, 'showOs' => false, 'showIp' => false];

Laravel

Install the PHP library using Composer:

composer require stackmash/stackmash-laravel

Add the following details to your .env file, replacing with your keys:

STACKMASH_KEY=YOUR_PUBLIC_KEY
STACKMASH_SECRET=YOUR_PRIVATE_KEY

Create a notification:

Stackmash::action('general', 'You have a new notification', ['Hello' => 'Stackmash!']);

WordPress

Download the Stackmash WordPress Plugin, we recommend using the latest WordPress version.

Download plugin

Or download: https://cdn.stackmash.com/plugins/stackmash.zip

Install the plugin by uploading the ZIP file to the plugin uploader in your WordPress dashboard.

Then go to Stackmash in your WordPress dashboard and enter your project keys.

You can change the category names to match up with the categories added to your project on Stackmash. If you do not want to receive notifications for a particular action, simply remove the category name.

Note: please note that the WordPress plugin is still in beta. If you have any problems please contact our support.


Java

First you will need to install the OkHttp package. You can view the OkHttp docs here.

Then, in your Java app you can define the following variables:

String public_key = "qfW69aOczYBj1euGSGlihLDTqIqaYoSgl9Yj";
String private_key = "2NwofncmfQRedJqZ6NbvcexghOvTesAvAscJ2JyNbMdEmGrWQPHKqvobmoEc";
String category = "tests";
String title = "You have a new notification";
// Set your body as a JSON string
String body = "{\\\"Hello\\\":\\\"World!\\\"}";

You will then need to make your POST request using the following code:

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody requestBody = RequestBody.create(mediaType, "{\"public_key\": \"" + public_key + "\",\"private_key\": \"" + private_key + "\",\"category\": \"" + category + "\",\"title\": \"" + title + "\",\"body\": \"" + body + "\"}");
Request request = new Request.Builder()
	.url("https://api.stackmash.com/api/notification/create")
	.post(requestBody)
	.addHeader("Accept", "application/json")
	.addHeader("Content-Type", "application/json")
	.build();

try {
	Response response = client.newCall(request).execute();
} catch (IOException e) {
	e.printStackTrace();
}

NodeJS

For NodeJS we strongly recommend installing the request module. You can do this by running:

npm i request

Once installed, you will need to include the request module into your Node app:

var request = require('request');

To send a request to Stackmash you first need to have your parameters ready:

var public_key = 'YOUR_PUBLIC_KEY';
var private_key = 'YOUR_PRIVATE_KEY';

var category = 'general';
var title = 'You have a new notification';
var body = {"Hello": "Stackmash!"};

Then use the following code to setup the correct options for the request:

var options = {
	url: 'https://api.stackmash.com/api/notification/create',
	method: 'POST',
	headers: {
		'Accept': 'application/json',
		'Content-Type': 'application/json'
	},
	form: {
		public_key: public_key,
		private_key: private_key,
		category: category,
		title: title,
		body: JSON.stringify(body)
	}
};

You can then make the request to the server:

request(options, function (error, response, body)
{
	// If there is no error and we get a 201 created code
	if(!error && response.statusCode == 201)
	{
		// You can also turn the JSON string into a Javascript object
		console.log(JSON.parse(body));
	}
});

Python

Integrating Stackmash with Python is super simple. First you will need the requests library to send a request to the Stackmash servers. To do this you will need to run either:

pip install requests

Or:

pipenv install requests

You can learn more about installing requests by clicking here. Once installed you will need to import the library:

import requests

Then assign your parameters:

public_key = 'YOUR_PUBLIC_KEY'
private_key = 'YOUR_PRIVATE_KEY'
category = 'general'
title = 'You have a new notification'
body = '{"Hello":"Stackmash!"}'

Then create the parameters for the request:

url = "https://api.stackmash.com/api/notification/create"
data = {"public_key": public_key, "private_key": private_key, "category": category, "title": title, "body": body}
headers = {"Accept": "application/json"}

And then send the request:

response = requests.post(url, data = data, headers = headers)

To view the response you can add this:

print(response.text)

And that’s it! To find out more about the requests library click here.


.NET

For use with .NET, we strongly recommend installing the RestSharp package to make sending post requests to the Stackmash servers easier. So first you will need to install RestSharp using NuGet. Once you have installed the package, you will need the following declaration:

using RestSharp;

Once you have this, define your variables as strings:

string public_key = "YOUR_PUBLIC_KEY";
string private_key = "YOUR_PRIVATE_KEY";
string category = "general";
string title = "You have a new notification";
string body = "{\"Hello\":\"Stackmash!\"}";

Then define the client and request, this code does not need to be altered:

var client = new RestClient("https://api.stackmash.com");
var request = new RestRequest("api/notification/create", Method.POST);

Then we set our headers:

request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");

The parameters are then added to the body:

request.AddJsonBody(new { public_key = public_key, private_key = private_key, category = category, title = title, body = body });

Finally, the request can be executed:

IRestResponse response = client.Execute(request);

You can then take the response and view it by running:

Console.WriteLine(response.Content);

If you would like to know more about the RestSharp package, the documentation can be viewed here.


Ruby

We highly recommend installing the HTTParty Gem to make sending HTTP requests a breeze. To install HTTParty, you will need to run:

gem install httparty

Once installed, import HTTParty to your project:

require 'httparty'

Then define your HTTP body:

body = {
	public_key: "YOUR_PUBLIC_KEY",
	private_key: "YOUR_PRIVATE_KEY",
	category: "general",
	title: "You have a new notification",
	body: "Hello Stackmash!"
}

After this, you can then send the request:

response = HTTParty.post('https://api.stackmash.com/api/notification/create', :headers => {'Accept': 'application/json', 'Content-Type': 'application/json'}, :query => body)

This is enough to send a notification to Stackmash, but if needed, you can do some simple validation:

if response.code != 200 && response.code != 201
	puts "#{response.body}"
end

This line of code will display the body if the request was not successful. Learn more about the response here. If you would like to know more about HTTParty, visit the documentation.


Other/cURL

Creating a notification is as simple as sending a HTTP POST request. If you would like to know how this can be done using any language, click the link below.

View the docs

You can also use cURL, an example is shown below:

curl -X POST \
  https://api.stackmash.com/api/notification/create \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"public_key": "YOUR_PUBLIC_KEY",
	"private_key": "YOUR_PRIVATE_KEY",
	"category": "general",
	"title": "You have a new notification",
	"body": "{\"Hello\": \"World!\"}"
}'

© 2019 Alto Care Systems Ltd T/A Stackmash. All rights reserved.

Alto Care Systems Limited is a company registered in England and Wales (No. 11486134) whose registered office is at Hardwick House, Oldmedow Road, King's Lynn, PE30 4JJ.