Skip to content

Examples

Here are examples of how to use Notifery in different programming languages.

Bash

Terminal window
curl -X POST https://api.notifery.com/event \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{
"title": "Deployment Complete",
"message": "Application deployed successfully",
"zone": "my-zone"
}'

JavaScript

// Using fetch API
const sendEvent = async () => {
try {
const response = await fetch('https://api.notifery.com/event', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key',
},
body: JSON.stringify({
title: 'Database Backup Complete',
message: 'Successfully backed up 1.2GB of data',
zone: 'my-zone',
group: 'database',
}),
})
const data = await response.json()
console.log('Event created:', data)
} catch (error) {
console.error('Error sending event:', error)
}
}
sendEvent()

Python

import requests
def send_event():
response = requests.post(
'https://api.notifery.com/event',
headers={
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key'
},
json={
'title': 'Daily Report',
'message': 'Daily processing completed with 0 errors',
'zone': 'my-zone',
'group': 'reports',
'code': 0
}
)
if response.status_code == 200:
print('Event created:', response.json())
else:
print('Error:', response.status_code, response.text)
send_event()

PHP

<?php
$url = 'https://api.notifery.com/event';
$data = [
'title' => 'User Registration',
'message' => 'New user registered: user@example.com',
'zone' => 'my-zone',
'group' => 'users'
];
$options = [
'http' => [
'header' => "Content-type: application/json\r\nX-API-Key: your-api-key",
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
echo "Error sending event";
} else {
echo "Event created: " . $result;
}
?>

Go

package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
// Prepare the data
data := map[string]interface{}{
"title": "Cron Job Complete",
"message": "Scheduled task executed successfully",
"zone": "my-zone",
"group": "cron",
}
jsonData, err := json.Marshal(data)
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return
}
// Create the request
req, err := http.NewRequest("POST", "https://api.notifery.com/event", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// Set headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-API-Key", "your-api-key")
// Send the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
// Read the response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("Response:", string(body))
}

Ruby

require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('https://api.notifery.com/event')
request = Net::HTTP::Post.new(uri)
request.content_type = 'application/json'
request['X-Api-Key'] = 'your-api-key'
request.body = JSON.dump({
'title' => 'Payment Processed',
'message' => 'Successfully processed payment of $99.99',
'zone' => 'my-zone',
'group' => 'payments'
})
req_options = {
use_ssl: uri.scheme == 'https'
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
if response.code == '200'
puts "Event created: #{response.body}"
else
puts "Error: #{response.code} - #{response.body}"
end