Can anyone tell me how to show OneSignal Subscribed User Count in our App

Can anyone tell me how to show OneSignal Subscribed User Count in our App

I’m trying to show OneSignal Total Subscribed user count in My App if anyone know any method tell me.

<?php
$apiKey = 'YOUR_ONE_SIGNAL_REST_API_KEY';
$appId = 'YOUR_ONE_SIGNAL_APP_ID';

$url = "https://onesignal.com/api/v1/apps/$appId";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Basic ' . $apiKey
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
    die('Error fetching data from OneSignal.');
}
$responseData = json_decode($response, true);
if (isset($responseData['messageable_players'])) {
    $playersCount = $responseData['players'];
    $messageable_players = $responseData['messageable_players']; 
    echo "Total subscriber count: $playersCount";
    echo "<br>";
    echo "Total Active subscriber count: $messageable_players";
    echo "<br><hr><br>";
       echo "$response";
} else {
    echo "Subscriber count not found in response.";
    echo "<br><hr><br>";
    echo "$response";
}
?>

You can use this code to get all the info about your application
and as per requirement, I have already made 2 variables
you can use them and print accordingly

$playersCount is for Total Subscribers
$messageable_players is for Active Subscribers

Regards @Akash_Kinha

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.