The V2 version API is switched to the standard REST request, and most of the compatibility processing has been done for the V1 version API; users should use the new REST API when using the V2 version.
| Field | Type | Description |
|---|---|---|
| title (optional) | string | Notification title (font size would be larger than the body) |
| subtitle (optional) | string | Notification subtitle |
| body | string | Notification content |
| device_key | string | The key for each device |
| device_keys (optional) | array | Used for batch pushing |
| level (optional) | string | 'critical', 'active', 'timeSensitive', 'passive' |
| volume (optional) | string | The ringtone volume for critical alert notification. |
| badge (optional) | integer | The number displayed next to App icon (Apple Developer) |
| call (optional) | string | Must be 1, The ringtone will continue to play for 30 seconds |
| autoCopy (optional) | string | Must be 1 |
| copy (optional) | string | The value to be copied |
| sound (optional) | string | Value from here, and custom ringtones are also available |
| icon (optional) | string | An url to the icon, available only on iOS 15 or later |
| group (optional) | string | The group of the notification |
| ciphertext (optional) | string | The ciphertext of encrypted push notifications |
| isArchive (optional) | string | Value must be 1. Whether or not should be archived by the app |
| ttl (optional) | integer | Time to live for archived messages, in seconds. Expired archived messages are deleted automatically |
| url (optional) | string | Url that will jump when click notification |
| action (optional) | string | Set to "none", tap notifications do nothing |
curl -X "POST" "http://127.0.0.1:8080/push" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"body": "Test Bark Server",
"device_key": "ynJ5Ft4atkMkWeo2PAvFhF",
"title": "bleem",
"badge": 1,
"sound": "minuet",
"icon": "https://day.app/assets/images/avatar.jpg",
"group": "test",
"url": "https://mritd.com"
}'package main
import (
"fmt"
"io/ioutil"
"net/http"
"bytes"
)
func sendPush() {
// push (POST http://127.0.0.1:8080/push)
json := []byte(`{"body": "Test Bark Server","device_key": "nysrshcqielvoxsa","title": "bleem", "badge": 1, "icon": "https://day.app/assets/images/avatar.jpg", "group": "test", "url": "https://mritd.com","sound": "minuet"}`)
body := bytes.NewBuffer(json)
// Create client
client := &http.Client{}
// Create request
req, err := http.NewRequest("POST", "http://127.0.0.1:8080/push", body)
if err != nil {
fmt.Println("Failure : ", err)
}
// Headers
req.Header.Add("Content-Type", "application/json; charset=utf-8")
// Fetch Request
resp, err := client.Do(req)
if err != nil {
fmt.Println("Failure : ", err)
}
// Read Response Body
respBody, _ := ioutil.ReadAll(resp.Body)
// Display Results
fmt.Println("response Status : ", resp.Status)
fmt.Println("response Headers : ", resp.Header)
fmt.Println("response Body : ", string(respBody))
}# Install the Python Requests library:
# `pip install requests`
import requests
import json
def send_request():
# push
# POST http://127.0.0.1:8080/push
try:
response = requests.post(
url="http://127.0.0.1:8080/push",
headers={
"Content-Type": "application/json; charset=utf-8",
},
data=json.dumps({
"body": "Test Bark Server",
"device_key": "nysrshcqielvoxsa",
"title": "bleem",
"sound": "minuet",
"badge": 1,
"icon": "https://day.app/assets/images/avatar.jpg",
"group": "test",
"url": "https://mritd.com"
})
)
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))
print('Response HTTP Response Body: {content}'.format(
content=response.content))
except requests.exceptions.RequestException:
print('HTTP Request failed')import java.io.IOException;
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class SendRequest
{
public static void main(String[] args) {
sendRequest();
}
private static void sendRequest() {
// push (POST )
try {
// Create request
Content content = Request.Post("http://127.0.0.1:8080/push")
// Add headers
.addHeader("Content-Type", "application/json; charset=utf-8")
// Add body
.bodyString("{\"body\": \"Test Bark Server\",\"device_key\": \"nysrshcqielvoxsa\",\"title\": \"bleem\",\"url\": \"https://mritd.com\", \"group\": \"test\",\"sound\": \"minuet\"}", ContentType.APPLICATION_JSON)
// Fetch request and return content
.execute().returnContent();
// Print content
System.out.println(content);
}
catch (IOException e) { System.out.println(e); }
}
}// request push
(function (callback) {
"use strict";
const httpTransport = require("http");
const responseEncoding = "utf8";
const httpOptions = {
hostname: "127.0.0.1",
port: "8080",
path: "/push",
method: "POST",
headers: { "Content-Type": "application/json; charset=utf-8" },
};
httpOptions.headers["User-Agent"] = "node " + process.version;
// Using Basic Auth {"username":"","password":""}
// Paw Store Cookies option is not supported
const request = httpTransport
.request(httpOptions, (res) => {
let responseBufs = [];
let responseStr = "";
res
.on("data", (chunk) => {
if (Buffer.isBuffer(chunk)) {
responseBufs.push(chunk);
} else {
responseStr = responseStr + chunk;
}
})
.on("end", () => {
responseStr =
responseBufs.length > 0
? Buffer.concat(responseBufs).toString(responseEncoding)
: responseStr;
callback(null, res.statusCode, res.headers, responseStr);
});
})
.setTimeout(0)
.on("error", (error) => {
callback(error);
});
request.write(
'{"device_key":"nysrshcqielvoxsa","body":"Test Bark Server","title":"bleem","sound":"minuet","url":"https://mritd.com", "group":"test"}',
);
request.end();
})((error, statusCode, headers, body) => {
console.log("ERROR:", error);
console.log("STATUS:", statusCode);
console.log("HEADERS:", JSON.stringify(headers));
console.log("BODY:", body);
});$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'http://127.0.0.1:8080/push',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"body": "Test Bark Server",
"device_key": "ynJ5Ft4atkMkWeo2PAvFhF",
"title": "bleem",
"badge": 1,
"sound": "minuet",
"icon": "https://day.app/assets/images/avatar.jpg",
"group": "test",
"url": "https://mritd.com"
}',
CURLOPT_HTTPHEADER => [
'Content-Type: application/json; charset=utf-8',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;curl "http://127.0.0.1:8080/ping"curl "http://127.0.0.1:8080/healthz"curl "http://127.0.0.1:8080/info"