2017 © Pedro Peláez
 

library onesignal-php-api

OneSignal API for PHP

image

norkunas/onesignal-php-api

OneSignal API for PHP

  • Saturday, April 28, 2018
  • by norkunas
  • Repository
  • 14 Watchers
  • 132 Stars
  • 173,400 Installations
  • PHP
  • 8 Dependents
  • 1 Suggesters
  • 57 Forks
  • 3 Open issues
  • 31 Versions
  • 11 % Grown

The README.md

OneSignal API for PHP

Latest Stable Version Scrutinizer Code Quality Total Downloads GitHub Workflow Status Software License, (*1)

Install

Note: All examples are for v2, if you are using PHP <7.3 please read v1 documentation., (*2)

This packages requires a PSR-18 HTTP client and PSR-17 HTTP factories to work. You can choose any from psr/http-client-implementation and psr/http-factory-implementation, (*3)

Example with Symfony HttpClient and nyholm/psr7 http factories, install it with Composer:, (*4)

composer require symfony/http-client nyholm/psr7 norkunas/onesignal-php-api

And now configure the OneSignal api client:, (*5)

<?php

declare(strict_types=1);

use OneSignal\Config;
use OneSignal\OneSignal;
use Symfony\Component\HttpClient\Psr18Client;
use Nyholm\Psr7\Factory\Psr17Factory;

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

$config = new Config('your_application_id', 'your_application_auth_key', 'your_auth_key');
$httpClient = new Psr18Client();
$requestFactory = $streamFactory = new Psr17Factory();

$oneSignal = new OneSignal($config, $httpClient, $requestFactory, $streamFactory);

How to use this library

Applications API

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

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

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

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

Create a new OneSignal app (official documentation):, (*8)

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

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

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

Create Segments (official documentation):, (*10)

$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,'],
    ],
]);

Delete Segments (official documentation):, (*11)

$oneSignal->apps()->deleteSegment('application_id', 'segment_id');

View the details of all the outcomes associated with your app (official documentation):, (*12)

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 API

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

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

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

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

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

use OneSignal\Devices;

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

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

$oneSignal->devices()->update('device_id', [
    'session_count' => 2,
    'ip' => '127.0.0.1', // Optional. New IP Address of your device
]);

Update an existing device's tags in one of your OneSignal apps using the External User ID (official documentation):, (*17)

$externalUserId = '12345';
$response = $oneSignal->devices()->editTags($externalUserId, [
    'tags' => [
        'a' => '1',
        'foo' => '',
    ],
]);

Notifications API

View the details of multiple notifications (official documentation):, (*18)

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

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

$notification = $oneSignal->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):, (*20)

$oneSignal->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):, (*21)

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

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

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

Notification History (official documentation):, (*23)

$oneSignal->notifications()->history('notification_id', [
    'events' => 'clicked', // or 'sent'
    'email' => 'your_email@email.com',
]);

Questions?

If you have any questions please open a discussion., (*24)

License

This library is released under the MIT License. See the bundled LICENSE file for details., (*25)

The Versions

28/04 2018

dev-master

9999999-dev

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

19/04 2018

1.0.x-dev

1.0.9999999.9999999-dev

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

19/04 2018

v1.1.0

1.1.0.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

11/04 2018

v1.0.4

1.0.4.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

18/02 2018

v1.0.3

1.0.3.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

01/12 2017

v1.0.2

1.0.2.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

26/10 2017

0.1.x-dev

0.1.9999999.9999999-dev

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

26/10 2017

v0.2.0

0.2.0.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

28/09 2017

v1.0.1

1.0.1.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

13/09 2017

v0.1.17

0.1.17.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

13/09 2017

v1.0.0

1.0.0.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

28/04 2017

v0.1.16

0.1.16.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

05/04 2017

v0.1.15

0.1.15.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

24/02 2017

v0.1.14

0.1.14.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

10/02 2017

v0.1.13

0.1.13.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

05/12 2016

v0.1.12

0.1.12.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

21/11 2016

v0.1.11

0.1.11.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

11/11 2016

v0.1.10

0.1.10.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

05/10 2016

dev-test

dev-test

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal notifications

01/08 2016

v0.1.9

0.1.9.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

06/06 2016

v0.1.8

0.1.8.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

27/05 2016

v0.1.7

0.1.7.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

26/05 2016

v0.1.6

0.1.6.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

10/03 2016

v1.0.0-rc2

1.0.0.0-RC2

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

24/02 2016

v1.0.0-rc1

1.0.0.0-RC1

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

13/01 2016

v0.1.5

0.1.5.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

20/11 2015

v0.1.4

0.1.4.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

15/09 2015

v0.1.3

0.1.3.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

01/09 2015

v0.1.2

0.1.2.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

20/07 2015

v0.1.1

0.1.1.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas Norkūnas

api onesignal

24/05 2015

v0.1.0

0.1.0.0

OneSignal API for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tomas

api onesignal