Skip to content

OneSignal/onesignal-rust-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust API client for onesignal-rust-api

Building with an AI agent or LLM? See AGENTS.md for an agent-oriented integration guide — authentication, calling conventions, idempotent retries, and the full API reference.

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

For more information, please visit https://onesignal.com

  • API version: 5.9.0
  • Package version: 5.9.0

Installation

Add to Cargo.toml under [dependencies]:

onesignal-rust-api = "5.9.0"

Configuration

Every SDK requires authentication via API keys. Two key types are available:

  • REST API Key — required for most endpoints (sending notifications, managing users, etc.). Found in your app's Settings > Keys & IDs.
  • Organization API Key — only required for organization-level endpoints like creating or listing apps. Found in Organization Settings.

Warning: Store your API keys in environment variables or a secrets manager. Never commit them to source control.

use onesignal_rust_api::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
}

Send a push notification

use onesignal_rust_api::apis::default_api;
use onesignal_rust_api::models::{Notification, LanguageStringMap};
use onesignal_rust_api::models::notification::TargetChannelType;

let mut contents = LanguageStringMap::new();
contents.en = Some("Hello from OneSignal!".to_string());

let mut headings = LanguageStringMap::new();
headings.en = Some("Push Notification".to_string());

let mut notification = Notification::new("YOUR_APP_ID".to_string());
notification.contents = Some(Box::new(contents));
notification.headings = Some(Box::new(headings));
notification.included_segments = Some(vec!["Subscribed Users".to_string()]);

let config = create_configuration();
let response = default_api::create_notification(&config, notification).await;

Send an email

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.target_channel = Some(TargetChannelType::Email);

let response = default_api::create_notification(&config, notification).await;

Send an SMS

let mut contents = LanguageStringMap::new();
contents.en = Some("Your SMS message content here".to_string());

let mut notification = Notification::new("YOUR_APP_ID".to_string());
notification.contents = Some(Box::new(contents));
notification.included_segments = Some(vec!["Subscribed Users".to_string()]);
notification.target_channel = Some(TargetChannelType::Sms);
notification.sms_from = Some("+15551234567".to_string());

let response = default_api::create_notification(&config, notification).await;

Full API reference

The complete list of API endpoints and their parameters is available in the DefaultApi documentation.

For the underlying REST API, see the OneSignal API reference.

About

OneSignal Rust API Client SDK library

Topics

Resources

License

Stars

12 stars

Watchers

27 watching

Forks

Packages

 
 
 

Contributors

Languages