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

Onsite Messaging REST API

This is the PushAlert REST API documentation for Onsite Messaging. 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/onsite-messaging/stats Get consolidated stats about all your campaigns including total views, clicks, emails collected and overall CTR.
GET https://api.pushalert.co/rest/v2/onsite-messaging/stats/$CAMPAIGN_ID Get detailed stats about a particular campaign, including total views, clicks, emails collected, and overall CTR.
POST https://api.pushalert.co/rest/v2/onsite-messaging/update/$CAMPAIGN_ID Change the campaign status from Published to Unpublished or vice versa.

Overall Stats

GET /rest/v2/onsite-messaging/stats

Get consolidated stats for your account, including total views, total clicks, total emails collected, and overall click-through rate (CTR).

Resource Information

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

Response Parameters

Parameter Type Description
views Integer Total number of views from all your campaigns to date.
cliks Integer Total number of clicks to date.
emails Integer Total number of emails collected through all your campaigns to date.
ctr Double Overall click-through-rate (CTR) to date, based on total clicks and emails collected.

Example

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

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

	$curlUrl = "https://api.pushalert.co/rest/v2/onsite-messaging/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,
	"views": 2102,
	"clicks": 79,
	"emails": 123,
	"ctr": "9.61%",
}
Copy

Campaign Stats

GET /rest/v2/onsite-messaging/stats/$CAMPAIGN_ID

Get detailed stats about a specific campaign, including total views, clicks, emails collected, and overall click-through rate (CTR).

Resource Information

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

Method Parameters

Parameter Type Description
$CAMPAIGN_ID Integer ID of the campaign.

Response Parameters

Parameter Type Description
views Integer Total number of views for the given campaign. This is a dynamic stat and updates throughout the day.
clicks Integer Number of clicks for the campaign. This stat updates dynamically throughout the day.
emails Integer Total number of emails collected through the campaign, this is not a static statistic. It keeps on updating as your campaign reaches more people.
ctr Double Overall click-through-rate (CTR) to date, based on total cliks and emails.

Example

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

	$campaignID = 12;
	$apiKey = "YOUR_API_KEY";

	$curlUrl = "https://api.pushalert.co/rest/v2/onsite-messaging/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["views"]}, Clicks: {$output["clicks"]}, Emails: {$output["emails"]} and CTR: {$output["ctr"]}%";
	}
	else {
		//Others like bad request
	}
?>
Copy
Output
{
	"success": true,
	"views": 2102,
	"clicks": 79,
	"emails": 123,
	"ctr": "9.61%",
}
Copy

Change Campaign State

GET /rest/v2/onsite-messaging/update/$CAMPAIGN_ID

Change a campaign's state to Publish or Unpublish.

Resource Information

Method POST
URL https://api.pushalert.co/rest/v2/onsite-messaging/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/onsite-messaging/update/15 \
    -H "Authorization: api_key=<insert api key here>" \
    -d "status=1" 
<?php

	$campaign_id = 15; //Your campaign ID

	$new_status = 1;

	$apiKey = "YOUR_API_KEY";

	$curlUrl = "https://api.pushalert.co/rest/v2/onsite-messaging/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