PushFyreAccelerate. Ignite. Broadcast.

Send API code examples

The same push send written for Go, Node.js, Java, Python, .NET, Ruby, and PHP.

Each sample calls POST /api/v1/push/send with the same body. Read the server key from the environment as PUSHFYRE_SERVER_KEY. See API authentication for the headers and Send notifications with the API for every field.

Replace the host with your PushFyre API host, and replace the app id and tenant id with the values from the portal. The server key is the app API key. Keep it on the server that sends the campaign. Do not ship it inside a mobile app or a web page.

The sample targets one device id and sends to web, Android, and iOS. Change segmentQuery when the audience is a saved segment instead of one device. A 403 means a header is missing or the key was revoked. A 400 means a field in the body is missing or invalid. The campaign then shows in the same report as a send from the portal.

Pick the language your server already uses. The JSON body does not change between them. campaignName is the name you will see in the portal. channels lists where the message can go. payload.title and payload.message are required. launchUrl is the address opened when the notification is tapped. Leave a channel out when that platform should not receive this campaign.

body, err := json.Marshal(map[string]any{
    "campaignName": "order-shipped",
    "type":         "simple",
    "channels":     []string{"web", "android", "ios"},
    "segmentQuery": map[string]any{
        "tags": map[string][]string{"deviceId": {"user-1001"}},
    },
    "payload": map[string]string{
        "title":     "Your order shipped",
        "message":   "Track it from the Orders tab.",
        "launchUrl": "https://yourapp.com/orders",
    },
})
req, err := http.NewRequest(http.MethodPost, "https://push.example.com/api/v1/push/send", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-app-id", "app_49e692ad")
req.Header.Set("x-tenant-id", "<your-tenant-id>")
req.Header.Set("x-api-key", os.Getenv("PUSHFYRE_SERVER_KEY"))
res, err := http.DefaultClient.Do(req)
defer res.Body.Close()