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
This API client was generated by the OpenAPI Generator project. By using the openapi-spec from a remote server, you can easily generate an API client.
org.openapitools.codegen.languages.RustClientCodegen
GitHub repository https://github.com/onesignal/onesignal-rust-api
You can install this library as a crate dependency https://crates.io/crates/onesignal-rust-api.
Put the package under your project folder in a directory named onesignal
and add the following to Cargo.toml
under [dependencies]
:
onesignal = { path = "./onesignal" }
```rust use onesignal::*; use onesignal::apis::configuration::Configuration; use onesignal::models::filter_expressions::RelationType; use onesignal::models::{App, FilterExpressions, Notification, Player, Segment, StringMap, UpdatePlayerTagsRequestBody};
```
```rust
const APPID: &str = "
```
rust
fn create_configuration() -> Box<Configuration> {
let mut configuration = apis::configuration::Configuration::new();
configuration.app_key_token = Some(String::from(APP_KEY_TOKEN));
configuration.user_key_token = Some(String::from(USER_KEY_TOKEN));
Box::new(configuration)
}
```rust
fn createnotification() -> Box
string_map.en = Some(String::from("Rust test notification"));
notification.contents = Some(Box::new(string_map));
notification.is_chrome_web = Some(true);
notification.is_any_web = Some(true);
notification.included_segments = Some(vec![String::from("Subscribed Users")]);
Box::new(notification)
} ```
```rust async fn sendnotification() { // Prepare configuration and the notification objects let configuration = createconfiguration(); let notification = create_notification();
// Send notification to the server
let create_notification_response = apis::default_api::create_notification(&configuration, *notification).await;
// Check the result
if let Ok(ref created_notification) = create_notification_response {
println!("Created notification id: {}", created_notification.id);
}
if let Err(ref created_notification_error) = create_notification_response {
println!("Created notification error: {}", created_notification_error.to_string());
}
} ```
```rust async fn cancelschedulednotification() { let configuration = createconfiguration(); let mut notification = createnotification(); let sendafter = Utc::now().checkedaddsigned(Duration::seconds(30)); notification.sendafter = Some(String::from(sendafter.unwrap().torfc2822()));
let create_notification_response =
apis::default_api::create_notification(&configuration, *notification.clone()).await;
let cancel_notification_response =
apis::default_api::cancel_notification(
&configuration, APP_ID, &create_notification_response.unwrap().id).await;
assert_ok!(&cancel_notification_response);
assert!(cancel_notification_response.unwrap().success.unwrap());
} ```
```rust async fn getnotification() { let configuration = createconfiguration(); let notification = create_notification();
let create_notification_response =
apis::default_api::create_notification(&configuration, *notification.clone()).await;
let get_notification_response =
apis::default_api::get_notification(
&configuration, APP_ID, &create_notification_response.unwrap().id).await;
assert_ok!(&get_notification_response);
assert!(get_notification_response.unwrap().id.unwrap().len() > 0);
} ```
```rust async fn getmultiplenotifications() { let configuration = create_configuration();
// Limit: 100
// Offset: 0
// Kind: 1
let get_notifications_response =
apis::default_api::get_notifications(
&configuration, APP_ID, Some(100), Some(0), Some(1)).await;
assert_ok!(&get_notifications_response);
assert!(get_notifications_response.unwrap().notifications.unwrap().len() > 0);
} ```
rust
fn create_player() -> Box<Player> {
let mut player = Box::new(Player::new("Rust Test Player".to_string(), 1));
player.app_id = Some(APP_ID.to_string());
player
}
```rust async fn createandgetplayer() { let configuration = createconfiguration(); let player = create_player();
let create_player_response =
apis::default_api::create_player(&configuration, *player).await;
let get_player_response =
apis::default_api::get_player(
&configuration, APP_ID, &create_player_response.unwrap().id.unwrap(), None).await;
assert_ok!(&get_player_response);
assert!(get_player_response.unwrap().id.len() > 0);
} ```
```rust async fn updateplayer() { let configuration = createconfiguration(); let player = createplayer(); let mut updatedplayer = createplayer(); updatedplayer.externaluserid = Some(String::from("test_user"));
let create_player_response =
apis::default_api::create_player(&configuration, *player).await;
let update_player_response =
apis::default_api::update_player(
&configuration, &create_player_response.unwrap().id.unwrap(), *updated_player).await;
assert_ok!(&update_player_response);
assert!(update_player_response.unwrap().success.unwrap());
} ```
```rust async fn updateplayertags() { let configuration = create_configuration();
let mut updated_player_tags_request_body= UpdatePlayerTagsRequestBody::new();
let tag_value = json!({"test_tag": 1});
updated_player_tags_request_body.tags = Some(tag_value);
let update_player_tags_response =
apis::default_api::update_player_tags(
&configuration,
APP_ID,
"test_user",
Some(updated_player_tags_request_body)).await;
assert_ok!(&update_player_tags_response);
assert!(update_player_tags_response.unwrap().success.unwrap());
} ```
```rust async fn getmultipleplayers() { let configuration = create_configuration();
// Limit: 10
// Offset: 0
let get_players_response =
apis::default_api::get_players(&configuration, APP_ID, Some(10), None).await;
assert_ok!(&get_players_response);
assert!(get_players_response.unwrap().players.unwrap().len() > 0);
} ```
```rust
fn createsegment(name: String) -> Box
Box::new(segment)
} ```
```rust async fn createanddeletesegment() { let configuration = createconfiguration(); let segment = createsegment("testsegment");
let create_segment_response =
apis::default_api::create_segments(&configuration, APP_ID, Some(*segment)).await;
let delete_segment_response =
apis::default_api::delete_segments(
&configuration, APP_ID, &create_segment_response.unwrap().id.unwrap()).await;
assert_ok!(&delete_segment_response);
assert!(delete_segment_response.unwrap().success.unwrap());
} ```
```rust async fn getapp() { let configuration = createconfiguration();
let get_app_response =
apis::default_api::get_app(&configuration, APP_ID).await;
assert_ok!(&get_app_response);
assert!(get_app_response.unwrap().id.len() > 0);
} ```
```rust async fn updateapp() { let configuration = createconfiguration(); let mut app = App::new(APPID.tostring()); app.sitename = Some("rusttestchangedname".to_string());
let update_app_response =
apis::default_api::update_app(&configuration, APP_ID, app).await;
assert_ok!(&update_app_response);
assert!(update_app_response.unwrap().id.len() > 0);
} ```
```rust async fn getmultipleapps() { let configuration = create_configuration();
let get_apps_response =
apis::default_api::get_apps(&configuration).await;
assert_ok!(&get_apps_response);
assert!(get_apps_response.unwrap().len() > 0);
} ```
```rust async fn getoutcomes() { let configuration = createconfiguration(); let outcomenames = "ossessionduration.count,osclick.count"; let outcometimerange = "1d"; let outcomeplatforms = "5"; let outcomeattribution = "direct";
let get_outcomes_response =
apis::default_api::get_outcomes(
&configuration,
APP_ID,
outcome_names,
None,
Some(outcome_time_range),
Some(outcome_platforms),
Some(outcome_attribution)).await;
assert_ok!(&get_outcomes_response);
assert!(get_outcomes_response.unwrap().outcomes.unwrap().len() > 0);
} ```
All URIs are relative to https://onesignal.com/api/v1
Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- DefaultApi | cancelnotification | DELETE /notifications/{notificationid} | Stop a scheduled or currently outgoing notification DefaultApi | createapp | POST /apps | Create an app *DefaultApi* | createnotification | POST /notifications | Create notification DefaultApi | createplayer | POST /players | Add a device *DefaultApi* | createsegments | POST /apps/{appid}/segments | Create Segments *DefaultApi* | deleteplayer | DELETE /players/{playerid} | Delete a user record *DefaultApi* | deletesegments | DELETE /apps/{appid}/segments/{segmentid} | Delete Segments DefaultApi | exportplayers | POST /players/csvexport?appid={appid} | CSV export DefaultApi | getapp | GET /apps/{appid} | View an app DefaultApi | getapps | GET /apps | View apps *DefaultApi* | getnotification | GET /notifications/{notificationid} | View notification *DefaultApi* | getnotificationhistory | POST /notifications/{notificationid}/history | Notification History DefaultApi | getnotifications | GET /notifications | View notifications *DefaultApi* | getoutcomes | GET /apps/{appid}/outcomes | View Outcomes *DefaultApi* | getplayer | GET /players/{playerid} | View device *DefaultApi* | getplayers | GET /players | View devices DefaultApi | updateapp | PUT /apps/{appid} | Update an app DefaultApi | updateplayer | PUT /players/{playerid} | Edit device DefaultApi | updateplayertags | PUT /apps/{appid}/users/{externaluser_id} | Edit tags with external user id
To get access to the crate's generated documentation, use:
cargo doc --open
All URIs are relative to https://onesignal.com/api/v1
Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- DefaultApi | cancelnotification | DELETE /notifications/{notificationid} | Stop a scheduled or currently outgoing notification DefaultApi | createapp | POST /apps | Create an app *DefaultApi* | createnotification | POST /notifications | Create notification DefaultApi | createplayer | POST /players | Add a device *DefaultApi* | createsegments | POST /apps/{appid}/segments | Create Segments *DefaultApi* | deleteplayer | DELETE /players/{playerid} | Delete a user record *DefaultApi* | deletesegments | DELETE /apps/{appid}/segments/{segmentid} | Delete Segments DefaultApi | exportplayers | POST /players/csvexport?appid={appid} | CSV export DefaultApi | getapp | GET /apps/{appid} | View an app DefaultApi | getapps | GET /apps | View apps *DefaultApi* | getnotification | GET /notifications/{notificationid} | View notification *DefaultApi* | getnotificationhistory | POST /notifications/{notificationid}/history | Notification History DefaultApi | getnotifications | GET /notifications | View notifications *DefaultApi* | getoutcomes | GET /apps/{appid}/outcomes | View Outcomes *DefaultApi* | getplayer | GET /players/{playerid} | View device *DefaultApi* | getplayers | GET /players | View devices DefaultApi | updateapp | PUT /apps/{appid} | Update an app DefaultApi | updateplayer | PUT /players/{playerid} | Edit device DefaultApi | updateplayertags | PUT /apps/{appid}/users/{externaluser_id} | Edit tags with external user id
To get access to the crate's generated documentation, use:
cargo doc --open
devrel@onesignal.com