{"id":19251046,"url":"https://github.com/onesignal/onesignal-cpp-api","last_synced_at":"2025-02-23T16:38:47.991Z","repository":{"id":38332318,"uuid":"486761314","full_name":"OneSignal/onesignal-cpp-api","owner":"OneSignal","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-22T17:26:49.000Z","size":381,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":33,"default_branch":"main","last_synced_at":"2025-02-16T16:56:14.293Z","etag":null,"topics":["cpp","email","in-app-messaging","onesignal","push-notifications","sms"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OneSignal.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2022-04-28T22:05:10.000Z","updated_at":"2025-01-22T00:11:46.000Z","dependencies_parsed_at":"2024-11-09T18:21:40.396Z","dependency_job_id":"6cc773f3-4627-4cd6-ada1-91d8f8e5938d","html_url":"https://github.com/OneSignal/onesignal-cpp-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneSignal%2Fonesignal-cpp-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneSignal%2Fonesignal-cpp-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneSignal%2Fonesignal-cpp-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneSignal%2Fonesignal-cpp-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OneSignal","download_url":"https://codeload.github.com/OneSignal/onesignal-cpp-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240347761,"owners_count":19787230,"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":["cpp","email","in-app-messaging","onesignal","push-notifications","sms"],"created_at":"2024-11-09T18:19:44.567Z","updated_at":"2025-02-23T16:38:47.985Z","avatar_url":"https://github.com/OneSignal.png","language":"C++","readme":"# C++ API client\n\nA powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com\n\n## Overview\nThis API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI spec](https://openapis.org) from a remote server, you can easily generate an API client.\n\n- API version: 1.3.0\n- Package version: 2.1.0\n- Build package: org.openapitools.codegen.languages.CppRestSdkClientCodegen\nFor more information, please visit [https://onesignal.com](https://onesignal.com)\n\n- API namespace: com.onesignal.client.api\n- Model namespace: com.onesignal.client.model\n\n## Installation\n\n### Prerequisites\n\nInstall [cpprestsdk](https://github.com/Microsoft/cpprestsdk).\n\n- Windows: `vcpkg install cpprestsdk cpprestsdk:x64-windows boost-uuid boost-uuid:x64-windows`\n- Mac:\n    `brew install cpprestsdk`\n    `brew install openssl`\n- Linux: `sudo apt-get install libcpprest-dev`\n\n### Cmake integration\nYou can `cmake --install .` and then use `find_package(CppRestOneSignalAPIClient REQUIRED)`.\nAlternatively you can have it as a subdirectory as in the example below.\n\n\nTake a look on our test `CMakeLists.txt`:\n```\ncmake_minimum_required(VERSION 3.22)\nproject(CppRestOneSignalAPIClientTest)\n\nset(CMAKE_CXX_STANDARD 14)\n\n# Test dependencies\nfind_package(Catch2 REQUIRED)\n\n# OneSignal Client Library\nadd_subdirectory(deps/onesignal)\n\n# Executables for tests\nadd_executable(tests test.cpp)\n\ntarget_link_libraries(tests Catch2::Catch2 CppRestOneSignalAPIClient)\n```\n\n### Build\n\n```sh\ncmake -DCMAKE_CXX_FLAGS=\"-I/usr/local/include -I/usr/local/Cellar/include -I/usr/local/opt/include\" \\\n-DCMAKE_MODULE_LINKER_FLAGS=\"-L/usr/local/lib -L/usr/local/Cellar/lib -L/usr/local/opt/lib\" \\\n-DCMAKE_EXE_LINKER_FLAGS=\"-L/usr/local/lib -L/usr/local/Cellar/lib -L/usr/local/opt/lib -L/usr/local/opt/openssl/lib\" \\\n-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \\\n-DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib \\\nmake\n```\n\n\u003e Note, if you are getting compilation errors related to missing dependencies, and you installed them using different package managers\nlike Homebrew, you may need to alter cmake flags with appropriate paths.\n\n### Build on Windows with Visual Studio (VS2017)\n\n- Right click on folder containing source code\n- Select 'Open in visual studio'\n- Once visual studio opens, CMake should show up in top menu bar.\n- Select CMake \u003e Build All.\n\n*Note: If the CMake menu item doesn't show up in Visual Studio, CMake\nfor Visual Studio must be installed. In this case, open the 'Visual Studio\nInstaller' application. Select 'modify' Visual Studio 2017. Make sure\n'Desktop Development with C++' is installed, and specifically that 'Visual\nC++ tools for CMake' is selected in the 'Installation Details' section.\n\nAlso be sure to review the CMakeLists.txt file. Edits are likely required.*\n\n## How to use\n### Initializing the OneSignal CPP Client library\n```cpp\n#include \"CppRestOneSignalAPIClient/ApiClient.h\"\n#include \"CppRestOneSignalAPIClient/ApiConfiguration.h\"\n#include \"CppRestOneSignalAPIClient/api/DefaultApi.h\"\n\nusing com::onesignal::client::api::ApiClient;\nusing com::onesignal::client::api::ApiConfiguration;\nusing com::onesignal::client::api::DefaultApi;\n\nusing utility::string_t;\nusing utility::conversions::to_string_t;\n\nconst std::string APP_ID = \"\u003cYOUR_APP_ID\u003e\";\nconst std::string APP_KEY_TOKEN = \"\u003cYOUR_APP_KEY_TOKEN\u003e\";\nconst std::string USER_KEY_TOKEN = \"\u003cYOUR_USER_KEY_TOKEN\u003e\";\n\nstatic DefaultApi * createApi() {\n    // Settings up the client\n    const auto configuration = ApiClient::getDefaultConfiguration();\n    configuration-\u003esetAppKeyToken(APP_KEY_TOKEN);\n    configuration-\u003esetUserKeyToken(USER_KEY_TOKEN);\n\n    const auto apiClient = std::make_shared\u003cApiClient\u003e(configuration);\n\n    return new DefaultApi(apiClient);\n}\n\n```\n\n\u003e If you use this library synchronously, make sure you call .get() to wait for the response and wrap it in a try-catch block, so you can see the errors if there are any.\n\n### Creating a notification model\n```cpp\nstatic std::shared_ptr\u003cNotification\u003e createNotification() {\n    const auto notification = std::make_shared\u003cNotification\u003e();\n    notification-\u003esetAppId(APP_ID);\n\n    const auto content = std::make_shared\u003cStringMap\u003e();\n    content-\u003esetEn(to_string_t(\"OneSignal C++ Client Test: Create notification\"));\n    std::vector\u003cstring_t\u003e vect{ to_string_t(\"Active Users\") };\n\n    notification-\u003esetContents(content);\n    notification-\u003esetIncludedSegments(vect);\n    notification-\u003esetIsAnyWeb(true);\n    notification-\u003esetIsChrome(true);\n\n    return notification;\n}\n```\n\n### Sending a notification using Filters\n```cpp\nconst auto api = createApi();\nstd::vector\u003cstd::shared_ptr\u003cFilter\u003e\u003e filters;\n\n// Creating a notification\nconst auto notification = createNotification();\n\n// Find all the users that have not spent any amount in USD on IAP.\n// https://documentation.onesignal.com/reference/create-notification#send-to-users-based-on-filters\nconst auto filter1 = std::make_shared\u003cFilter\u003e();\nfilter1-\u003esetField(to_string_t(\"amount_spent\"));\nfilter1-\u003esetRelation(to_string_t(\"=\"));\nfilter1-\u003esetValue(\"0\");\nfilters.push_back(filter1);\n\nnotification-\u003esetFilters(filters);\n\n// Send a notification\nconst auto response = api-\u003ecreateNotification(notification);\nconst auto \u0026 responseData = response.get();\n\n// Check the result\nCHECK(responseData-\u003egetId().size() \u003e 0);\nCHECK_FALSE(responseData-\u003eerrorsIsSet());\n```\n\n### Sending a notification\n```cpp\nconst auto api = createApi();\n\n// Creating a notification\nconst auto notification = createNotification();\n\n// Send a notification\nconst auto response = api-\u003ecreateNotification(notification);\nconst auto \u0026 responseData = response.get();\n\n// Check the result\nCHECK(responseData-\u003egetId().size() \u003e 0);\nCHECK_FALSE(responseData-\u003eerrorsIsSet());\n```\n\n### Sending and canceling scheduled notification\n```cpp\nconst auto api = createApi();\n\n// Create a scheduled notification\nconst auto notification = createNotification();\n\nnotification-\u003esetSendAfter(utility::datetime().utc_now() + utility::datetime().from_hours(1));\n\n// Send a notification\nconst auto sendResponse = api-\u003ecreateNotification(notification);\nconst auto \u0026 sendResponseData = sendResponse.get();\n\n// Cancel a scheduled notification\nconst auto cancelResponse = api-\u003ecancelNotification(APP_ID, sendResponseData-\u003egetId());\nconst auto \u0026 cancelResponseData = cancelResponse.get();\n\n// Check the result\nCHECK(cancelResponseData-\u003eisSuccess());\n```\n\n### Getting a notification\n```cpp\nconst auto api = createApi();\n\n// Get a notification\nconst auto getResponse = api-\u003egetNotification(APP_ID, \"\u003cyour_notification_id\u003e\");\nconst auto \u0026 getResponseData = getResponse.get();\n\n// Check the result\nCHECK(getResponseData-\u003egetId() == sendResponseData-\u003egetId());\n```\n\n### Getting a list of notifications\n```cpp\nconst auto api = createApi();\n\n// Creating a notification\nconst auto notification = createNotification();\n\n// Get list of notification with the limit of 10\nconst auto getResponse = api-\u003egetNotifications(APP_ID, 10, boost::none, boost::none);\nconst auto \u0026 notificationSlice = getResponse.get();\n\n// Check the result\nCHECK(notificationSlice-\u003egetNotifications().size() == 10);\n```\n\n### Creating and getting a player\n```cpp\nstatic std::shared_ptr\u003cPlayer\u003e createPlayer() {\n    const auto player = std::make_shared\u003cPlayer\u003e();\n\n    player-\u003esetAppId(APP_ID);\n    player-\u003esetIdentifier(\"Id_example\");\n    player-\u003esetDeviceType(1);\n\n    return player;\n}\n```\n\n```cpp\nconst auto api = createApi();\n\n// Creating a player\nconst auto player = createPlayer();\n\n// Send a create request\nconst auto createResponse = api-\u003ecreatePlayer(player);\nconst auto \u0026 createResponseData = createResponse.get();\n\n// Send a get request\nconst auto getResponse = api-\u003egetPlayer(APP_ID, createResponseData-\u003egetId(), boost::none);\nconst auto \u0026 getResponseData = getResponse.get();\n\nCHECK(createResponseData-\u003eisSuccess());\nCHECK(getResponseData-\u003egetId() == createResponseData-\u003egetId());\n```\n\n### Creating and deleting a segment\n```cpp\nstatic std::shared_ptr\u003cSegment\u003e createSegment(string_t segmentName) {\n    // Setting up filters\n    const auto filterExpressions = std::make_shared\u003cFilterExpressions\u003e();\n    filterExpressions-\u003esetField(to_string_t(\"session_count\"));\n    filterExpressions-\u003esetRelation(to_string_t(\"\u003e\"));\n    filterExpressions-\u003esetValue(\"1\");\n\n    std::vector\u003cstd::shared_ptr\u003cFilterExpressions\u003e\u003e vect;\n    vect.push_back(filterExpressions);\n\n    // Setting up the segment\n    const auto segment = std::make_shared\u003cSegment\u003e();\n    segment-\u003esetName(segmentName);\n    segment-\u003esetFilters(vect);\n\n    return segment;\n}\n```\n\n```cpp\nconst auto api = createApi();\n\n// Creating a segment\nconst auto segment = createSegment(\"\u003ctest_segment_name\u003e\");\n\n// Send a create request\nconst auto createResponse = api-\u003ecreateSegments(APP_ID, segment).get();\n\nsleep(10);\n\n// Send a delete request\nconst auto deleteResponse = api-\u003edeleteSegments(APP_ID, createResponse-\u003egetId()).get();\n\n// Check the result\nCHECK(deleteResponse-\u003eisSuccess());\n```\n\n### Getting an App\n```cpp\nconst auto api = createApi();\n\n// Send a get request\nconst auto app = api-\u003egetApp(APP_ID).get();\n\n// Check the result\nCHECK(app-\u003egetId() == APP_ID);\n```\n\n### Getting outcomes\n```cpp\nconst auto api = createApi();\n\n// Set up the request\nconst auto outcomeNames = to_string_t(\"os__session_duration.count,os__click.count\");\nconst auto outcomeTimeRange = to_string_t(\"1d\");\nconst auto outcomePlatforms = to_string_t(\"5\");\nconst auto outcomeAttribution = to_string_t(\"direct\");\n\n// Send the request\nconst auto outcomesResponse = api-\u003egetOutcomes(APP_ID,\n                                               outcomeNames,\n                                               boost::none,\n                                               outcomeTimeRange,\n                                               outcomePlatforms,\n                                               outcomeAttribution);\nconst auto outcomes = outcomesResponse.get()-\u003egetOutcomes();\n\n// Check the result\nCHECK(outcomes.size() \u003e 0);\n```\n\n### Begin Live Activity event\n```cpp\nconst auto beginLiveActivityRequest = std::make_shared\u003cBeginLiveActivityRequest\u003e();\nbeginLiveActivityRequest-\u003esetPushToken(\"push_token_example\");\nbeginLiveActivityRequest-\u003esetSubscriptionId(\"player id example\");\n\napi-\u003ebeginLiveActivity(APP_ID, \"activity id example\", beginLiveActivityRequest);\n```\n\n### Update Live Activity event\n```cpp\nconst auto updateLiveActivityRequest = std::make_shared\u003cUpdateLiveActivityRequest\u003e();\nupdateLiveActivityRequest-\u003esetName(\"contents\");\nupdateLiveActivityRequest-\u003esetEvent(\"update\");\nconst auto eventUpdates = std::make_shared\u003cObject\u003e();\neventUpdates-\u003esetValue(to_string_t(\"data\"), 1);\nupdateLiveActivityRequest-\u003esetEventUpdates(eventUpdates);\n\napi-\u003eupdateLiveActivity(APP_ID, \"activity id example\", updateLiveActivityRequest);\n```\n\n### End Live Activity event\n```cpp\napi-\u003eendLiveActivity(APP_ID, \"activity id example\", \"player id example\");\n```\n\n## Users\n### Create User\n```cpp\n// Creating a user model to be send to the server\nconst auto user = std::make_shared\u003cUser\u003e();\nconst auto aliasLabel = \"\u003cALIAS_LABEL\u003e\";\nconst auto aliasId = \"\u003cALIAS_ID\u003e\";\nconst auto pushToken = \"\u003cDEVICE_PUSH_TOKEN\u003e\";\n\nstd::map\u003cutility::string_t, utility::string_t\u003e identity = {};\nidentity[aliasLabel] = aliasId;\nuser-\u003esetIdentity(identity);\n\ncom::onesignal::client::model::SubscriptionObject subscriptionObject;\nsubscriptionObject.setToken(pushToken);\nsubscriptionObject.setType(\"iOSPush\");\nstd::vector\u003cstd::shared_ptr\u003ccom::onesignal::client::model::SubscriptionObject\u003e\u003e subscriptions = {\n        std::make_shared\u003ccom::onesignal::client::model::SubscriptionObject\u003e(subscriptionObject)\n};\n\n// Sending to to the server\nconst auto createUserResponse = api-\u003ecreateUser(APP_ID, user).get();\n```\n\n### Fetch user by alias\n```cpp\nconst auto fetchUserResponse = api-\u003efetchUser(APP_ID, \u003cALIAS_LABEL\u003e, \u003cALIAS_ID\u003e).get();\n```\n\n### Update user\n```cpp\nconst auto updateUserRequest = std::make_shared\u003cUpdateUserRequest\u003e();\nconst auto propertiesObject = std::make_shared\u003cPropertiesObject\u003e();\npropertiesObject-\u003esetLanguage(\"fr\");\nupdateUserRequest-\u003esetProperties(propertiesObject);\n\nconst auto updateUserResponse = api-\u003eupdateUser(APP_ID, \"\u003cALIAS_LABEL\u003e\", \"\u003cALIAS_ID\u003e\", updateUserRequest).get();\nCHECK(updateUserResponse-\u003egetProperties()-\u003egetLanguage() == \"fr\");\n```\n\n### Delete user\n```cpp\napi-\u003edeleteUser(APP_ID, \"\u003cALIAS_LABEL\u003e\", \"\u003cALIAS_ID\u003e\").get();\n```\n\n### Create subscription\n```cpp\nconst auto subscriptionObject = std::make_shared\u003cSubscriptionObject\u003e();\nsubscriptionObject-\u003esetType(\"AndroidPush\");\nsubscriptionObject-\u003esetToken(\"\u003cDEVICE_PUSH_TOKEN\u003e\");\nconst auto createSubscriptionRequestBody = std::make_shared\u003cCreateSubscriptionRequestBody\u003e();\ncreateSubscriptionRequestBody-\u003esetSubscription(subscriptionObject);\n\nconst auto createSubscriptionResponse = api-\u003ecreateSubscription(APP_ID, \"\u003cALIAS_LABEL\u003e\", \"\u003cALIAS_ID\u003e\",\n                                                                createSubscriptionRequestBody).get();\n\nCHECK(createSubscriptionResponse-\u003egetSubscription()-\u003egetToken().length() != 0);\n```\n\n### Update subscription\n```cpp\nsubscriptionObject-\u003esetType(\"AndroidPush\");\nsubscriptionObject-\u003esetToken(\"\u003cDEVICE_PUSH_TOKEN\u003e\");\nconst auto updateSubscriptionRequestBody = std::make_shared\u003cUpdateSubscriptionRequestBody\u003e();\nupdateSubscriptionRequestBody-\u003esetSubscription(subscriptionObject);\n\napi-\u003eupdateSubscription(APP_ID, \"\u003cSUBSCRIPTION_ID\u003e\", updateSubscriptionRequestBody).get();\n```\n\n### Delete subscription\n```cpp\napi-\u003edeleteSubscription(APP_ID, \"\u003cSUBSCRIPTION_ID\u003e\").get();\n```\n\n### Fetch aliases by subscription id\n```cpp\nconst auto fetchAliasesResponse = api-\u003efetchAliases(APP_ID, \"\u003cSUBSCRIPTION_ID\u003e\").get();\n```\n\n### Fetch aliases by an alias\n```cpp\nconst auto fetchUserIdentityResponse = api-\u003efetchUserIdentity(APP_ID, \"\u003cALIAS_LABEL\u003e\", \"\u003cALIAS_ID\u003e\").get();\n```\n\n### Fetch aliases by subscription id\n```cpp\nconst auto fetchAliasesResponse = api-\u003efetchAliases(APP_ID, \"\u003cSUBSCRIPTION_ID\u003e\").get();\n```\n\n### Identify user by subscription id\nBasically means that you want to add an alias to the user using subscription id.\n```cpp\nconst auto subscriptionId = \"\u003cSUBSCRIPTION_ID\u003e\";\nconst auto newAliasLabel = \"\u003cNEW_ALIAS_LABEL\u003e\";\nconst auto newAliasId = \"\u003cNEW_ALIAS_ID\u003e\";\nstd::map\u003cutility::string_t, utility::string_t\u003e identity = {};\nidentity[newAliasLabel] = newAliasId;\nuser-\u003esetIdentity(identity);\nconst auto userIdentityRequestBody = std::make_shared\u003cUserIdentityRequestBody\u003e();\nuserIdentityRequestBody-\u003esetIdentity(identity);\n\nconst auto identifyUserBySubscriptionIdResponse =\n        api-\u003eidentifyUserBySubscriptionId(APP_ID, subscriptionId, userIdentityRequestBody).get();\n\nCHECK(identifyUserBySubscriptionIdResponse-\u003egetIdentity()[newAliasLabel] == newAliasId);\n```\n\n### Identify user by an alias\nBasically means that you want to add an alias to the user using another alias.\n```cpp\nconst auto subscriptionId = \"\u003cSUBSCRIPTION_ID\u003e\";\nconst auto newAliasLabel = \"\u003cNEW_ALIAS_LABEL\u003e\";\nconst auto newAliasId = \"\u003cNEW_ALIAS_ID\u003e\";\nstd::map\u003cutility::string_t, utility::string_t\u003e identity = {};\nidentity[newAliasLabel] = newAliasId;\nuser-\u003esetIdentity(identity);\nconst auto userIdentityRequestBody = std::make_shared\u003cUserIdentityRequestBody\u003e();\nuserIdentityRequestBody-\u003esetIdentity(identity);\n\nconst auto identifyUserBySubscriptionIdResponse =\n        api-\u003eidentifyUserByAlias(APP_ID, \"\u003cALIAS_LABEL\u003e\", \"\u003cALIAS_ID\u003e\", userIdentityRequestBody).get();\n\nCHECK(identifyUserBySubscriptionIdResponse-\u003egetIdentity()[newAliasLabel] == newAliasId);\n```\n\n### Transfers subscription ownership\n```cpp\nconst auto transferSubscriptionRequestBody = std::make_shared\u003cTransferSubscriptionRequestBody\u003e();\nstd::map\u003cutility::string_t, utility::string_t\u003e identity = {};\nidentity[\"\u003cUSER_FROM_ALIAS_LABEL\u003e\"] = \"\u003cUSER_FROM_ALIAS_ID\u003e\";\ntransferSubscriptionRequestBody-\u003esetIdentity(identity);\n\nconst auto identifyUserByAliasResponse =\n        api-\u003etransferSubscription(APP_ID, \"\u003cUSER_TO_SUBSCRIPTION_ID\u003e\", transferSubscriptionRequestBody).get();\n```\n\n### Fetch IAMs\n```cpp\napi-\u003egetEligibleIams(APP_ID, \"\u003cSUBSCRIPTION_ID\u003e\").get();\n```\n\n## Author\n\ndevrel@onesignal.com\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonesignal%2Fonesignal-cpp-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonesignal%2Fonesignal-cpp-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonesignal%2Fonesignal-cpp-api/lists"}