Getting Started
How to use JustPush efficiently
Last updated
How to use JustPush efficiently
Last updated
The user manual is our manual and tutorial list explaining you on how to implement and use JustPush services. It describes the process of getting from downloading the app to working / implementing with various frameworks.
Find per programming language how you can send your first message. These examples do not use an SDK and are just setup to send your first message.
curl -X "POST" "https://api.justpush.io/messages" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"message": "My First Message",
"topic" : "Default",
"title": "Bingo! I've just received my first message",
"user": "REPLACE WITH API TOKEN"
}'
$response = file_get_contents("https://api.justpush.io/messages", false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => [
'Accept: application/json',
'Content-Type: application/json; charset=utf-8',
],
'content' => json_encode([
"message" => "My First Message",
"topic" => "Default",
"title" => "Bingo! I've just received my first message",
"user" => "REPLACE WITH API TOKEN"
]),
]
]));
echo $response;
fetch('https://api.justpush.io/messages', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify({
message: 'My First Message',
topic: 'Default',
title: "Bingo! I've just received my first message",
user: 'REPLACE WITH API TOKEN'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
async function sendMessage() {
const response = await fetch('https://api.justpush.io/messages', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify({
message: 'My First Message',
topic: 'Default',
title: "Bingo! I've just received my first message",
user: 'REPLACE WITH API TOKEN'
}),
});
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
}
const data = await response.json();
console.log(data);
}
sendMessage().catch(error => console.error('Error:', error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
message := map[string]string{
"message": "My First Message",
"topic": "Default",
"title": "Bingo! I've just received my first message",
"user": "REPLACE WITH API TOKEN",
}
jsonData, err := json.Marshal(message)
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return
}
resp, err := http.Post("https://api.justpush.io/messages", "application/json; charset=utf-8", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error making POST request:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Println("Request failed with status:", resp.Status)
return
}
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println("Response:", result)
}
import requests
url = "https://api.justpush.io/messages"
data = {
"message": "My First Message",
"topic": "Default",
"title": "Bingo! I've just received my first message",
"user": "REPLACE WITH API TOKEN"
}
response = requests.post(url, json=data, headers={
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8'
})
if response.status_code == 200:
print("Response:", response.json())
else:
print(f"Error: {response.status_code} - {response.text}")
require 'net/http'
require 'json'
require 'uri'
url = URI.parse("https://api.justpush.io/messages")
data = {
message: "My First Message",
topic: "Default",
title: "Bingo! I've just received my first message",
user: "REPLACE WITH API TOKEN"
}
json_data = data.to_json
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url.path, {
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8'
})
request.body = json_data
response = http.request(request)
if response.is_a?(Net::HTTPSuccess)
puts "Response: #{JSON.parse(response.body)}"
else
puts "Error: #{response.code} - #{response.message}"
end
Below example is applicable to a laravel command. After adding the command, use your terminal and command php artisan justpush:first
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
class SendNotification extends Command
{
protected $signature = 'justpush:first';
protected $description = 'Send a notification via the JustPush API';
public function handle()
{
$url = "https://api.justpush.io/messages";
$data = [
"message" => "My First Message",
"topic" => "Default",
"title" => "Bingo! I've just received my first message",
"user" => "REPLACE WITH API TOKEN",
];
$response = Http::withHeaders([
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
])->post($url, $data);
if ($response->successful()) {
$this->info('Notification sent successfully: ' . json_encode($response->json()));
} else {
$this->error('Failed to send notification: ' . $response->status() . ' - ' . $response->body());
}
return 0;
}
}
Checkout our SDK's to make your integration easier.