{"id":16761174,"url":"https://github.com/norkunas/onesignal-php-api","last_synced_at":"2025-04-12T20:38:59.537Z","repository":{"id":30795170,"uuid":"34352212","full_name":"norkunas/onesignal-php-api","owner":"norkunas","description":"OneSignal API for PHP","archived":false,"fork":false,"pushed_at":"2025-01-27T05:45:38.000Z","size":303,"stargazers_count":235,"open_issues_count":4,"forks_count":83,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-05T19:07:19.638Z","etag":null,"topics":["onesignal","onesignal-notifications","onesignal-php","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/norkunas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-21T21:06:46.000Z","updated_at":"2025-01-27T08:51:42.000Z","dependencies_parsed_at":"2023-02-14T04:46:10.280Z","dependency_job_id":"a3325a2a-430b-4ceb-932f-c57c8f00e5b4","html_url":"https://github.com/norkunas/onesignal-php-api","commit_stats":{"total_commits":243,"total_committers":27,"mean_commits":9.0,"dds":"0.13580246913580252","last_synced_commit":"1f6db112bb535d451c9cb78020725a18f826b364"},"previous_names":[],"tags_count":61,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norkunas%2Fonesignal-php-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norkunas%2Fonesignal-php-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norkunas%2Fonesignal-php-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norkunas%2Fonesignal-php-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/norkunas","download_url":"https://codeload.github.com/norkunas/onesignal-php-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631668,"owners_count":21136554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["onesignal","onesignal-notifications","onesignal-php","php"],"created_at":"2024-10-13T04:41:53.789Z","updated_at":"2025-04-12T20:38:59.503Z","avatar_url":"https://github.com/norkunas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OneSignal API for PHP\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/norkunas/onesignal-php-api.svg?color=%23039be5)](https://packagist.org/packages/norkunas/onesignal-php-api)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/norkunas/onesignal-php-api.svg?color=%23039be5)](https://scrutinizer-ci.com/g/norkunas/onesignal-php-api)\n[![Total Downloads](https://img.shields.io/packagist/dt/norkunas/onesignal-php-api.svg?color=%23039be5)](https://packagist.org/packages/norkunas/onesignal-php-api/stats)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/norkunas/onesignal-php-api/ci.yml?branch=master\u0026color=%23039be5)\n[![Software License](https://img.shields.io/github/license/norkunas/onesignal-php-api?color=%23039be5)](LICENSE)\n\n## Install\n\nNote: All examples are for v2, if you are using PHP \u003c7.3 please read [v1 documentation](https://github.com/norkunas/onesignal-php-api/blob/1.0/README.md).\n\nThis packages requires a PSR-18 HTTP client and PSR-17 HTTP factories to work. You can choose any from\n[psr/http-client-implementation](https://packagist.org/providers/psr/http-client-implementation)\nand [psr/http-factory-implementation](https://packagist.org/providers/psr/http-factory-implementation)\n\nExample with Symfony HttpClient and nyholm/psr7 http factories, install it with [Composer](https://getcomposer.org/):\n\n```\ncomposer require symfony/http-client nyholm/psr7 norkunas/onesignal-php-api\n```\n\nAnd now configure the OneSignal api client:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse OneSignal\\Config;\nuse OneSignal\\OneSignal;\nuse Symfony\\Component\\HttpClient\\Psr18Client;\nuse Nyholm\\Psr7\\Factory\\Psr17Factory;\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n$config = new Config('your_application_id', 'your_application_auth_key', 'your_auth_key');\n$httpClient = new Psr18Client();\n$requestFactory = $streamFactory = new Psr17Factory();\n\n$oneSignal = new OneSignal($config, $httpClient, $requestFactory, $streamFactory);\n```\n\n## How to use this library\n\n### Applications API\n\nView the details of all of your current OneSignal applications ([official documentation](https://documentation.onesignal.com/reference#view-apps-apps)):\n\n```php\n$myApps = $oneSignal-\u003eapps()-\u003egetAll();\n```\n\nView the details of a single OneSignal application ([official documentation](https://documentation.onesignal.com/reference#view-an-app)):\n\n```php\n$myApp = $oneSignal-\u003eapps()-\u003egetOne('application_id');\n```\n\nCreate a new OneSignal app ([official documentation](https://documentation.onesignal.com/reference#create-an-app)):\n\n```php\n$newApp = $oneSignal-\u003eapps()-\u003eadd([\n    'name' =\u003e 'app name',\n    'gcm_key' =\u003e 'key'\n]);\n```\n\nUpdate the name or configuration settings of OneSignal application ([official documentation](https://documentation.onesignal.com/reference#update-an-app)):\n\n```php\n$oneSignal-\u003eapps()-\u003eupdate('application_id', [\n    'name' =\u003e 'new app name'\n]);\n```\n\nCreate Segments ([official documentation](https://documentation.onesignal.com/reference#create-segments)):\n\n```php\n$oneSignal-\u003eapps()-\u003ecreateSegment('application_id', [\n    'name' =\u003e 'Segment Name',\n    'filters' =\u003e [\n        ['field' =\u003e 'session_count', 'relation' =\u003e '\u003e', 'value' =\u003e 1],\n        ['operator' =\u003e 'AND'],\n        ['field' =\u003e 'tag', 'relation' =\u003e '!=', 'key' =\u003e 'tag_key', 'value' =\u003e '1'],\n        ['operator' =\u003e 'OR'],\n        ['field' =\u003e 'last_session', 'relation' =\u003e '\u003c', 'value' =\u003e '30,'],\n    ],\n]);\n```\n\nDelete Segments ([official documentation](https://documentation.onesignal.com/reference#delete-segments)):\n\n```php\n$oneSignal-\u003eapps()-\u003edeleteSegment('application_id', 'segment_id');\n```\n\nView the details of all the outcomes associated with your app ([official documentation](https://documentation.onesignal.com/reference/view-outcomes)):\n\n```php\nuse OneSignal\\Apps;\nuse OneSignal\\Devices;\n\n$outcomes = $oneSignal-\u003eapps()-\u003eoutcomes('application_id', [\n    'outcome_names' =\u003e [\n        'os__session_duration.count',\n        'os__click.count',\n        'Sales, Purchase.sum',\n    ],\n    'outcome_time_range' =\u003e Apps::OUTCOME_TIME_RANGE_MONTH,\n    'outcome_platforms' =\u003e [Devices::IOS, Devices::ANDROID],\n    'outcome_attribution' =\u003e Apps::OUTCOME_ATTRIBUTION_DIRECT,\n]);\n```\n\n### Devices API\n\nView the details of multiple devices in one of your OneSignal apps ([official documentation](https://documentation.onesignal.com/reference#view-devices)):\n\n```php\n$devices = $oneSignal-\u003edevices()-\u003egetAll();\n```\n\nView the details of an existing device in your configured OneSignal application ([official documentation](https://documentation.onesignal.com/reference#view-device)):\n\n```php\n$device = $oneSignal-\u003edevices()-\u003egetOne('device_id');\n```\n\nRegister a new device to your configured OneSignal application ([official documentation](https://documentation.onesignal.com/reference#add-a-device)):\n\n```php\nuse OneSignal\\Devices;\n\n$newDevice = $oneSignal-\u003edevices()-\u003eadd([\n    'device_type' =\u003e Devices::ANDROID,\n    'identifier' =\u003e 'abcdefghijklmn',\n]);\n```\n\nUpdate an existing device in your configured OneSignal application ([official documentation](https://documentation.onesignal.com/reference#edit-device)):\n\n```php\n$oneSignal-\u003edevices()-\u003eupdate('device_id', [\n    'session_count' =\u003e 2,\n    'ip' =\u003e '127.0.0.1', // Optional. New IP Address of your device\n]);\n```\n\nUpdate an existing device's tags in one of your OneSignal apps using the External User ID ([official documentation](https://documentation.onesignal.com/reference/edit-tags-with-external-user-id)):\n\n```php\n$externalUserId = '12345';\n$response = $oneSignal-\u003edevices()-\u003eeditTags($externalUserId, [\n    'tags' =\u003e [\n        'a' =\u003e '1',\n        'foo' =\u003e '',\n    ],\n]);\n```\n\n### Notifications API\n\nView the details of multiple notifications ([official documentation](https://documentation.onesignal.com/reference#view-notifications)):\n\n```php\n$notifications = $oneSignal-\u003enotifications()-\u003egetAll();\n```\n\nGet the details of a single notification ([official documentation](https://documentation.onesignal.com/reference#view-notification)):\n\n```php\n$notification = $oneSignal-\u003enotifications()-\u003egetOne('notification_id');\n```\n\nCreate and send notifications or emails to a segment or individual users.\nYou may target users in one of three ways using this method: by Segment, by\nFilter, or by Device (at least one targeting parameter must be specified) ([official documentation](https://documentation.onesignal.com/reference#create-notification)):\n\n```php\n$oneSignal-\u003enotifications()-\u003eadd([\n    'contents' =\u003e [\n        'en' =\u003e 'Notification message'\n    ],\n    'included_segments' =\u003e ['All'],\n    'data' =\u003e ['foo' =\u003e 'bar'],\n    'isChrome' =\u003e true,\n    'send_after' =\u003e new \\DateTime('1 hour'),\n    'filters' =\u003e [\n        [\n            'field' =\u003e 'tag',\n            'key' =\u003e 'is_vip',\n            'relation' =\u003e '!=',\n            'value' =\u003e 'true',\n        ],\n        [\n            'operator' =\u003e 'OR',\n        ],\n        [\n            'field' =\u003e 'tag',\n            'key' =\u003e 'is_admin',\n            'relation' =\u003e '=',\n            'value' =\u003e 'true',\n        ],\n    ],\n    // ..other options\n]);\n```\n\nMark notification as opened ([official documentation](https://documentation.onesignal.com/reference#track-open)):\n\n```php\n$oneSignal-\u003enotifications()-\u003eopen('notification_id');\n```\n\nStop a scheduled or currently outgoing notification ([official documentation](https://documentation.onesignal.com/reference#cancel-notification)):\n\n```php\n$oneSignal-\u003enotifications()-\u003ecancel('notification_id');\n```\n\nNotification History ([official documentation](https://documentation.onesignal.com/reference#notification-history)):\n\n```php\n$oneSignal-\u003enotifications()-\u003ehistory('notification_id', [\n    'events' =\u003e 'clicked', // or 'sent'\n    'email' =\u003e 'your_email@email.com',\n]);\n```\n\n## Questions?\n\nIf you have any questions please [open a discussion](https://github.com/norkunas/onesignal-php-api/discussions/new).\n\n## License\n\nThis library is released under the MIT License. See the bundled [LICENSE](https://github.com/norkunas/onesignal-php-api/blob/master/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorkunas%2Fonesignal-php-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnorkunas%2Fonesignal-php-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorkunas%2Fonesignal-php-api/lists"}