Skip to content
OneSignal API for PHP
Branch: master
Clone or download
laimonas and norkunas IOS group&collapse parameters (#115)
* IOS group&collapse parameters

* Fix style issue
3
Latest commit 0d9e35f Mar 2, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src IOS group&collapse parameters (#115) Mar 2, 2019
tests IOS group&collapse parameters (#115) Mar 2, 2019
.editorconfig
.gitattributes
.gitignore
.styleci.yml Fix styleci Aug 28, 2018
.travis.yml
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Nov 10, 2017
LICENSE
README.md Add version constraint for guzzle adapter in readme Jan 15, 2019
composer.json Increase dependencies versions Jan 15, 2019
phpunit.xml.dist Add whitelist to phpunit config Apr 5, 2016

README.md

OneSignal API for PHP

Latest Stable Version Latest Unstable Version Scrutinizer Code Quality Total Downloads Build Status StyleCI License

Install

This packages requires an http adapter to work. You can choose any from php-http/client-implementation

Example with Guzzle v6 adapter, install it with Composer:

composer require php-http/guzzle6-adapter:^1.1 norkunas/onesignal-php-api

And now configure the service:

<?php

require __DIR__ . '/vendor/autoload.php';

use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
use Http\Client\Common\HttpMethodsClient as HttpClient;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use OneSignal\Config;
use OneSignal\OneSignal;

$config = new Config();
$config->setApplicationId('your_application_id');
$config->setApplicationAuthKey('your_application_auth_key');
$config->setUserAuthKey('your_auth_key');

$guzzle = new GuzzleClient([ // http://docs.guzzlephp.org/en/stable/quickstart.html
    // ..config
]);

$client = new HttpClient(new GuzzleAdapter($guzzle), new GuzzleMessageFactory());
$api = new OneSignal($config, $client);

How to use this library

Applications API

View the details of all of your current OneSignal applications (official documentation):

$myApps = $api->apps->getAll();

View the details of a single OneSignal application (official documentation):

$myApp = $api->apps->getOne('application_id');

Create a new OneSignal app (official documentation):

$newApp = $api->apps->add([
    'name' => 'app name',
    'gcm_key' => 'key'
]);

Update the name or configuration settings of OneSignal application (official documentation):

$api->apps->update('application_id', [
    'name' => 'new app name'
]);

Devices API

View the details of multiple devices in one of your OneSignal apps (official documentation):

$devices = $api->devices->getAll();

View the details of an existing device in your configured OneSignal application (official documentation):

$device = $api->devices->getOne('device_id');

Register a new device to your configured OneSignal application (official documentation):

$newDevice = $api->devices->add([
    'device_type' => Devices::ANDROID,
    'identifier' => 'abcdefghijklmn',
]);

Update an existing device in your configured OneSignal application (official documentation):

$api->devices->update('device_id', [
    'session_count' => 2,
]);

Notifications API

View the details of multiple notifications (official documentation):

$notifications = $api->notifications->getAll();

Get the details of a single notification (official documentation):

$notification = $api->notifications->getOne('notification_id');

Create and send notifications or emails to a segment or individual users. You may target users in one of three ways using this method: by Segment, by Filter, or by Device (at least one targeting parameter must be specified) (official documentation):

$api->notifications->add([
    'contents' => [
        'en' => 'Notification message'
    ],
    'included_segments' => ['All'],
    'data' => ['foo' => 'bar'],
    'isChrome' => true,
    'send_after' => new \DateTime('1 hour'),
    'filters' => [
        [
            'field' => 'tag',
            'key' => 'is_vip',
            'relation' => '!=',
            'value' => 'true',
        ],
        [
            'operator' => 'OR',
        ],
        [
            'field' => 'tag',
            'key' => 'is_admin',
            'relation' => '=',
            'value' => 'true',
        ],
    ],
    // ..other options
]));

Mark notification as opened (official documentation):

$api->notifications->open('notification_id');

Stop a scheduled or currently outgoing notification (official documentation):

$api->notifications->cancel('notification_id');

Questions?

If you have any questions please open an issue.

License

This library is released under the MIT License. See the bundled LICENSE file for details.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.