Install, configure, and use OneSignal server SDKs to send push notifications, emails, and SMS from your backend in Node.js, Python, Java, Go, PHP, Ruby, C#, and Rust.
All OneSignal server SDKs are generated from the same OpenAPI specification, so they share a consistent interface regardless of language. Each SDK wraps the OneSignal REST API and provides typed models for requests and responses.
use onesignal\client\api\DefaultApi;use onesignal\client\Configuration;use GuzzleHttp;$config = Configuration::getDefaultConfiguration() ->setRestApiKeyToken('YOUR_REST_API_KEY') ->setOrganizationApiKeyToken('YOUR_ORGANIZATION_API_KEY');$client = new DefaultApi( new GuzzleHttp\Client(), $config);
using OneSignalApi.Api;using OneSignalApi.Client;var config = new Configuration();config.BasePath = "https://api.onesignal.com";config.AccessToken = "YOUR_REST_API_KEY";var client = new DefaultApi(config);
use onesignal::apis::configuration::Configuration;fn create_configuration() -> Configuration { let mut config = Configuration::new(); config.rest_api_key_token = Some("YOUR_REST_API_KEY".to_string()); config.organization_api_key_token = Some("YOUR_ORGANIZATION_API_KEY".to_string()); config}
Store your API keys in environment variables or a secrets manager. Never commit them to source control.
Send push notifications to web and mobile Subscriptions by targeting a segment. These examples show the happy path — add error handling (try/catch, error callbacks) for production use.
use onesignal\client\model\Notification;use onesignal\client\model\StringMap;$content = new StringMap();$content->setEn('Hello from OneSignal!');$headings = new StringMap();$headings->setEn('Push Notification');$notification = new Notification();$notification->setAppId('YOUR_APP_ID');$notification->setContents($content);$notification->setHeadings($headings);$notification->setIncludedSegments(['Subscribed Users']);$response = $client->createNotification($notification);echo 'Notification ID: ' . $response->getId();
Send emails to Subscriptions with the email channel.
Node.js
Python
Java
Go
PHP
Ruby
C# (.NET)
Rust
const notification = new OneSignal.Notification();notification.app_id = 'YOUR_APP_ID';notification.email_subject = 'Important Update';notification.email_body = '<h1>Hello!</h1><p>This is an HTML email.</p>';notification.included_segments = ['Subscribed Users'];notification.channel_for_external_user_ids = 'email';const response = await client.createNotification(notification);
notification = onesignal.Notification( app_id='YOUR_APP_ID', email_subject='Important Update', email_body='<h1>Hello!</h1><p>This is an HTML email.</p>', included_segments=['Subscribed Users'], channel_for_external_user_ids='email',)response = client.create_notification(notification)
Notification notification = new Notification();notification.setAppId("YOUR_APP_ID");notification.setEmailSubject("Important Update");notification.setEmailBody("<h1>Hello!</h1><p>This is an HTML email.</p>");notification.setIncludedSegments(Arrays.asList("Subscribed Users"));notification.setChannelForExternalUserIds("email");var response = client.createNotification(notification);
notification := *onesignal.NewNotification("YOUR_APP_ID")notification.SetEmailSubject("Important Update")notification.SetEmailBody("<h1>Hello!</h1><p>This is an HTML email.</p>")notification.SetIncludedSegments([]string{"Subscribed Users"})notification.SetChannelForExternalUserIds("email")response, _, err := apiClient.DefaultApi .CreateNotification(orgAuth) .Notification(notification) .Execute()
$notification = new Notification();$notification->setAppId('YOUR_APP_ID');$notification->setEmailSubject('Important Update');$notification->setEmailBody('<h1>Hello!</h1><p>This is an HTML email.</p>');$notification->setIncludedSegments(['Subscribed Users']);$notification->setChannelForExternalUserIds('email');$response = $client->createNotification($notification);
notification = OneSignal::Notification.new({ app_id: 'YOUR_APP_ID', email_subject: 'Important Update', email_body: '<h1>Hello!</h1><p>This is an HTML email.</p>', included_segments: ['Subscribed Users'], channel_for_external_user_ids: 'email'})response = client.create_notification(notification)
var notification = new Notification(appId: "YOUR_APP_ID"){ EmailSubject = "Important Update", EmailBody = "<h1>Hello!</h1><p>This is an HTML email.</p>", IncludedSegments = new List<string> { "Subscribed Users" }, ChannelForExternalUserIds = "email"};var response = client.CreateNotification(notification);
let mut notification = Notification::new("YOUR_APP_ID".to_string());notification.email_subject = Some("Important Update".to_string());notification.email_body = Some("<h1>Hello!</h1><p>This is an HTML email.</p>".to_string());notification.included_segments = Some(vec!["Subscribed Users".to_string()]);notification.channel_for_external_user_ids = Some("email".to_string());let response = default_api::create_notification(&config, notification).await;
Each server SDK supports the same set of API endpoints. Refer to your SDK’s API documentation for the complete method list, including users, subscriptions, segments, templates, and more.
Use the SDK that matches your backend language. All server SDKs are generated from the same OpenAPI specification and support the same endpoints, so functionality is identical across languages.
What is the difference between the REST API Key and Organization API Key?
The REST API Key is scoped to a single app and is required for most operations like sending notifications and managing users. The Organization API Key is scoped to your organization and is only needed for creating or listing apps. Most integrations only need the REST API Key.
Can I use the REST API directly instead of an SDK?
Yes. The server SDKs are convenience wrappers around the OneSignal REST API. You can call the API directly using any HTTP client with the key authentication scheme (Authorization: key YOUR_REST_API_KEY).
Yes. All server SDKs are generated from the OneSignal OpenAPI specification using OpenAPI Generator. This ensures consistent API coverage across all languages.