Documentation: Push Notifications Onsite Messaging REST API
  1. Documentation
  2. REST API v2
  3. Message Hub

Message Hub REST API

This is the PushAlert REST API documentation for Message Hub. Below, you will find the complete listing of all the available endpoints. As we add more endpoints, they will be documented here as well.

If you need help using the REST API or have any issues with its implementation, please send a mail to us at api@pushalert.co.

REST API Endpoints List

Resource Description
GET https://api.pushalert.co/rest/v2/message-hub/stats Retrieve consolidated Message Hub statistics for your account, including total views, total clicks, total message opens, and overall click-through rate (CTR).
GET https://api.pushalert.co/rest/v2/message-hub/stats/$CAMPAIGN_ID Get detailed statistics for a specific Message Hub campaign, including total views, clicks, message opens, and overall CTR.
POST https://api.pushalert.co/rest/v2/message-hub/update/$CAMPAIGN_ID Update the Message Hub campaign status from Published to Unpublished or vice versa.

Overall Stats

GET /rest/v2/message-hub/stats

Returns aggregated Message Hub statistics, including total views, total clicks, total opens, and the overall click-through rate (CTR).

Resource Information

Method GET
URL https://api.pushalert.co/rest/v2/message-hub/stats
Requires authentication? Yes

Response Parameters

Parameter Type Description
viewed Integer Total number of campaign views to date.
opened Integer Total number of campaign opens recorded.
clicked Integer Total number of clicks generated across all campaigns.
ctr Double Overall click-through rate (CTR), calculated from total clicks and opens to date.

Example

curl https://api.pushalert.co/rest/v2/message-hub/stats \
    -H "Authorization: api_key=<insert api key here>"
<?php

	$notfID = 11;
	$apiKey = "YOUR_API_KEY";

	$curlUrl = "https://api.pushalert.co/rest/v2/message-hub/stats";

	$headers = Array();
	$headers[] = "Authorization: api_key=".$apiKey;

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $curlUrl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

	$result = curl_exec($ch);

	$output = json_decode($result, true);
	if($output["success"]) {
		echo "Views: {$output["views"]}, Clicks: {$output["clicks"]}, Emails: {$output["emails"]} and CTR: {$output["ctr"]}%";
	}
	else {
		//Others like bad request
	}
?>
Copy
Output
{
	"success": true,
	"viewed": 6433,
	"clicked": 1235,
	"opened": 382,
	"ctr": "19.20%",
}
Copy

Campaign Stats

GET /rest/v2/message-hub/stats/$CAMPAIGN_ID

Retrieve consolidated statistics for a specific campaign, including total views, total clicks, total message opens, and the overall click-through rate (CTR).

Resource Information

Method POST
URL https://api.pushalert.co/rest/v2/message-hub/stats/$CAMPAIGN_ID
Requires authentication? Yes

Method Parameters

Parameter Type Description
$CAMPAIGN_ID Integer ID of the campaign.

Response Parameters

Parameter Type Description
viewed Integer Total number of views recorded for this campaign.
clicked Integer Total number of clicks generated from this campaign.
opened Integer Total number of times the campaign message was opened.
ctr Double Click-through rate (CTR) for this campaign, calculated from total clicks and opens.

Example

curl https://api.pushalert.co/rest/v2/message-hub/stats/19 \
    -H "Authorization: api_key=<insert api key here>"
<?php

	$campaignID = 19;
	$apiKey = "YOUR_API_KEY";

	$curlUrl = "https://api.pushalert.co/rest/v2/message-hub/stats/$campaignID";

	$headers = Array();
	$headers[] = "Authorization: api_key=".$apiKey;

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $curlUrl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

	$result = curl_exec($ch);

	$output = json_decode($result, true);
	if($output["success"]) {
		echo "Views: {$output["viewed"]}, Clicks: {$output["cliked"]}, Opened: {$output["opened"]} and CTR: {$output["ctr"]}%";
	}
	else {
		//Others like bad request
	}
?>
Copy
Output
{
	"success": true,
	"views": 843,
	"clicks": 181,
	"emails": 61,
	"ctr": "21.47%",
}
Copy

Change Campaign State

GET /rest/v2/message-hub/update/$CAMPAIGN_ID

Change a campaign's state to Publish or Unpublish.

Resource Information

Method POST
URL https://api.pushalert.co/rest/v2/message-hub/update/$CAMPAIGN_ID
Requires authentication? Yes

Method Parameters

Parameter Type Description
$CAMPAIGN_ID Integer ID of the campaign.

Request Parameters

Parameter Type Description
status Integer Required 1 = Publish, 0 = Unpublish.

Response Parameters

Parameter Type Description
success boolean true if the status was changed successfully, otherwise false.

Example

curl https://api.pushalert.co/rest/v2/message-hub/update/15 \
    -H "Authorization: api_key=<insert api key here>" \
    -d "status=1" 
<?php

	$campaign_id = 2024; //Your campaign ID

	$new_status = 1;

	$apiKey = "YOUR_API_KEY";

	$curlUrl = "https://api.pushalert.co/rest/v2/message-hub/update/$campaign_id";

	$headers = Array();
	$headers[] = "Authorization: api_key=".$apiKey;

	$post_vars = array(
		"status" => $new_status
	);

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $curlUrl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_vars));
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

	$result = curl_exec($ch);

	$output = json_decode($result, true);
	if($output["success"]) {
                echo "Subscribers added successfully";
	}
	else {
		//Others like bad request
	}
?>
Copy
Output
{
	"success": true,
}
Copy