PHP code example of norkunas / onesignal-php-api
1. Go to this page and download the library: Download norkunas/onesignal-php-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
norkunas / onesignal-php-api example snippets
declare(strict_types=1);
use OneSignal\Config;
use OneSignal\OneSignal;
use Symfony\Component\HttpClient\Psr18Client;
use Nyholm\Psr7\Factory\Psr17Factory;
Psr17Factory();
$oneSignal = new OneSignal($config, $httpClient, $requestFactory, $streamFactory);
$myApps = $oneSignal->apps()->getAll();
$myApp = $oneSignal->apps()->getOne('application_id');
$newApp = $oneSignal->apps()->add([
'name' => 'app name',
'gcm_key' => 'key'
]);
$oneSignal->apps()->update('application_id', [
'name' => 'new app name'
]);
$oneSignal->apps()->createSegment('application_id', [
'name' => 'Segment Name',
'filters' => [
['field' => 'session_count', 'relation' => '>', 'value' => 1],
['operator' => 'AND'],
['field' => 'tag', 'relation' => '!=', 'key' => 'tag_key', 'value' => '1'],
['operator' => 'OR'],
['field' => 'last_session', 'relation' => '<', 'value' => '30,'],
],
]);
$oneSignal->apps()->deleteSegment('application_id', 'segment_id');
use OneSignal\Apps;
use OneSignal\Devices;
$outcomes = $oneSignal->apps()->outcomes('application_id', [
'outcome_names' => [
'os__session_duration.count',
'os__click.count',
'Sales, Purchase.sum',
],
'outcome_time_range' => Apps::OUTCOME_TIME_RANGE_MONTH,
'outcome_platforms' => [Devices::IOS, Devices::ANDROID],
'outcome_attribution' => Apps::OUTCOME_ATTRIBUTION_DIRECT,
]);
$devices = $oneSignal->devices()->getAll();
$device = $oneSignal->devices()->getOne('device_id');
use OneSignal\Devices;
$newDevice = $oneSignal->devices()->add([
'device_type' => Devices::ANDROID,
'identifier' => 'abcdefghijklmn',
]);
$oneSignal->devices()->update('device_id', [
'session_count' => 2,
'ip' => '127.0.0.1', // Optional. New IP Address of your device
]);
$externalUserId = '12345';
$response = $oneSignal->devices()->editTags($externalUserId, [
'tags' => [
'a' => '1',
'foo' => '',
],
]);
$notifications = $oneSignal->notifications()->getAll();
$notification = $oneSignal->notifications()->getOne('notification_id');
$oneSignal->notifications()->add([
'contents' => [
'en' => 'Notification message'
],
''filters' => [
[
'field' => 'tag',
'key' => 'is_vip',
'relation' => '!=',
'value' => 'true',
],
[
'operator' => 'OR',
],
[
'field' => 'tag',
'key' => 'is_admin',
'relation' => '=',
'value' => 'true',
],
],
// ..other options
]);
$oneSignal->notifications()->open('notification_id');
$oneSignal->notifications()->cancel('notification_id');
$oneSignal->notifications()->history('notification_id', [
'events' => 'clicked', // or 'sent'
'email' => '[email protected] ',
]);
composer