diff --git a/README.md b/README.md index 4c480aa..3bddb83 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ A powerful way to send personalized messages at scale and build effective custom For more information, please visit [https://onesignal.com](https://onesignal.com). -- API version: 5.6.0 -- Package version: 5.6.0 +- API version: 5.7.0 +- Package version: 5.7.0 ## Requirements diff --git a/composer.json b/composer.json index 02d5850..535ab19 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "onesignal/onesignal-php-api", - "version": "5.6.0", + "version": "5.7.0", "description": "A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com", "keywords": [ "onesignal", diff --git a/docs/Api/DefaultApi.md b/docs/Api/DefaultApi.md index 52c45ef..995dd79 100644 --- a/docs/Api/DefaultApi.md +++ b/docs/Api/DefaultApi.md @@ -64,7 +64,7 @@ Every operation requires either a **REST API Key** (App-scoped, used by ~77% of ### Error handling -When a request fails, the SDK throws `\onesignal\client\ApiException` (catch the generic `\Exception` as a fallback). The HTTP status code is `$e->getCode()` (int); the parsed error body is `$e->getResponseBody()`. Most envelopes match `{ "errors": ["..."] }` (an array of strings) but a few endpoints return `{ "errors": [{"code": ..., "title": ..., "meta": {...}}] }` (an array of structured error objects — used by `POST /apps/{app_id}/users` 409 conflict, see `CreateUserConflictResponse`), `{ "errors": "..." }` (string), or `{ "success": false }` (no `errors` field at all). Robust error-handling code should tolerate all four shapes. +When a request fails, the SDK throws `\onesignal\client\ApiException` (catch the generic `\Exception` as a fallback). The HTTP status code is `$e->getCode()` (int); the parsed error body is `$e->getResponseBody()`. Most envelopes match `{ "errors": ["..."] }` (an array of strings) but a few endpoints return `{ "errors": [{"code": ..., "title": ..., "meta": {...}}] }` (an array of structured error objects — used by `POST /apps/{app_id}/users` 409 conflict, see `CreateUserConflictResponse`), `{ "errors": "..." }` (string), or `{ "success": false }` (no `errors` field at all). Robust error-handling code should tolerate all four shapes. The `$e->getErrorMessages()` method does this for you, normalizing every shape to a flat `string[]` (empty when the body carries no `errors`). ### Polymorphic 200 from POST /notifications @@ -119,6 +119,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->cancelNotification: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->cancelNotification: ', $e->getMessage(), PHP_EOL; @@ -188,6 +191,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->copyTemplateToApp: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->copyTemplateToApp: ', $e->getMessage(), PHP_EOL; @@ -259,6 +265,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createAlias: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createAlias: ', $e->getMessage(), PHP_EOL; @@ -330,6 +339,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createAliasBySubscription: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createAliasBySubscription: ', $e->getMessage(), PHP_EOL; @@ -399,6 +411,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createApiKey: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createApiKey: ', $e->getMessage(), PHP_EOL; @@ -466,6 +481,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createApp: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createApp: ', $e->getMessage(), PHP_EOL; @@ -533,6 +551,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createCustomEvents: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createCustomEvents: ', $e->getMessage(), PHP_EOL; @@ -696,6 +717,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createSegment: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createSegment: ', $e->getMessage(), PHP_EOL; @@ -766,6 +790,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createSubscription: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createSubscription: ', $e->getMessage(), PHP_EOL; @@ -835,6 +862,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createTemplate: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createTemplate: ', $e->getMessage(), PHP_EOL; @@ -902,6 +932,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->createUser: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->createUser: ', $e->getMessage(), PHP_EOL; @@ -972,6 +1005,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->deleteAlias: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->deleteAlias: ', $e->getMessage(), PHP_EOL; @@ -1042,6 +1078,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->deleteApiKey: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->deleteApiKey: ', $e->getMessage(), PHP_EOL; @@ -1110,6 +1149,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->deleteSegment: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->deleteSegment: ', $e->getMessage(), PHP_EOL; @@ -1177,6 +1219,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->deleteSubscription: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->deleteSubscription: ', $e->getMessage(), PHP_EOL; @@ -1245,6 +1290,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->deleteTemplate: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->deleteTemplate: ', $e->getMessage(), PHP_EOL; @@ -1313,6 +1361,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->deleteUser: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->deleteUser: ', $e->getMessage(), PHP_EOL; @@ -1382,6 +1433,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->exportEvents: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->exportEvents: ', $e->getMessage(), PHP_EOL; @@ -1450,6 +1504,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->exportSubscriptions: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->exportSubscriptions: ', $e->getMessage(), PHP_EOL; @@ -1519,6 +1576,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getAliases: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getAliases: ', $e->getMessage(), PHP_EOL; @@ -1588,6 +1648,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getAliasesBySubscription: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getAliasesBySubscription: ', $e->getMessage(), PHP_EOL; @@ -1655,6 +1718,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getApp: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getApp: ', $e->getMessage(), PHP_EOL; @@ -1720,6 +1786,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getApps: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getApps: ', $e->getMessage(), PHP_EOL; @@ -1785,6 +1854,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getNotification: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getNotification: ', $e->getMessage(), PHP_EOL; @@ -1853,6 +1925,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getNotificationHistory: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getNotificationHistory: ', $e->getMessage(), PHP_EOL; @@ -1923,6 +1998,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getNotifications: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getNotifications: ', $e->getMessage(), PHP_EOL; @@ -1997,6 +2075,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getOutcomes: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getOutcomes: ', $e->getMessage(), PHP_EOL; @@ -2070,6 +2151,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getSegments: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getSegments: ', $e->getMessage(), PHP_EOL; @@ -2140,6 +2224,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->getUser: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->getUser: ', $e->getMessage(), PHP_EOL; @@ -2209,6 +2296,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->rotateApiKey: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->rotateApiKey: ', $e->getMessage(), PHP_EOL; @@ -2278,6 +2368,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->startLiveActivity: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->startLiveActivity: ', $e->getMessage(), PHP_EOL; @@ -2348,6 +2441,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->transferSubscription: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->transferSubscription: ', $e->getMessage(), PHP_EOL; @@ -2418,6 +2514,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->unsubscribeEmailWithToken: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->unsubscribeEmailWithToken: ', $e->getMessage(), PHP_EOL; @@ -2488,6 +2587,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->updateApiKey: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->updateApiKey: ', $e->getMessage(), PHP_EOL; @@ -2557,6 +2659,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->updateApp: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->updateApp: ', $e->getMessage(), PHP_EOL; @@ -2626,6 +2731,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->updateLiveActivity: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->updateLiveActivity: ', $e->getMessage(), PHP_EOL; @@ -2695,6 +2803,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->updateSubscription: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->updateSubscription: ', $e->getMessage(), PHP_EOL; @@ -2766,6 +2877,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->updateSubscriptionByToken: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->updateSubscriptionByToken: ', $e->getMessage(), PHP_EOL; @@ -2837,6 +2951,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->updateTemplate: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->updateTemplate: ', $e->getMessage(), PHP_EOL; @@ -2908,6 +3025,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->updateUser: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->updateUser: ', $e->getMessage(), PHP_EOL; @@ -2977,6 +3097,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->viewApiKeys: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->viewApiKeys: ', $e->getMessage(), PHP_EOL; @@ -3044,6 +3167,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->viewTemplate: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->viewTemplate: ', $e->getMessage(), PHP_EOL; @@ -3114,6 +3240,9 @@ try { } catch (\onesignal\client\ApiException $e) { echo 'Exception when calling DefaultApi->viewTemplates: ', $e->getMessage(), PHP_EOL; echo 'Status Code: ', $e->getCode(), PHP_EOL; + // getErrorMessages() flattens any error-envelope shape to a string[]; + // the raw body remains on getResponseBody(). + echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL; echo 'Response Body: ', $e->getResponseBody(), PHP_EOL; } catch (\Exception $e) { echo 'Exception when calling DefaultApi->viewTemplates: ', $e->getMessage(), PHP_EOL; diff --git a/lib/ApiException.php b/lib/ApiException.php index dbe7bf2..4911e3a 100644 --- a/lib/ApiException.php +++ b/lib/ApiException.php @@ -14,7 +14,7 @@ * * A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com * - * The version of the OpenAPI document: 5.6.0 + * The version of the OpenAPI document: 5.7.0 * Contact: devrel@onesignal.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.0.0-SNAPSHOT @@ -117,4 +117,71 @@ public function getResponseObject() { return $this->responseObject; } + + /** + * Gets the error messages carried by the response body, normalized to a + * flat string array regardless of which envelope shape the API returned + * (`{ "errors": "..." }`, `{ "errors": ["..."] }`, + * `{ "errors": [{ "code": ..., "title": ... }] }`, or an object map such as + * `{ "errors": { "invalid_aliases": {...} } }`, surfaced as `": "` + * entries). Returns an empty array when the body is not a recognizable error + * envelope. The raw body remains available via getResponseBody(). + * + * @return string[] + */ + public function getErrorMessages() + { + $body = $this->responseBody; + if (is_string($body)) { + $body = json_decode($body); + if ($body === null) { + return []; + } + } + + $errors = null; + if (is_object($body) && isset($body->errors)) { + $errors = $body->errors; + } elseif (is_array($body) && isset($body['errors'])) { + $errors = $body['errors']; + } + + if (is_string($errors)) { + return [$errors]; + } + if (is_array($errors)) { + $messages = []; + foreach ($errors as $error) { + if (is_string($error)) { + $messages[] = $error; + } elseif (is_object($error)) { + if (isset($error->title) && $error->title !== '') { + $messages[] = $error->title; + } elseif (isset($error->code)) { + $messages[] = $error->code; + } + } elseif (is_array($error)) { + if (isset($error['title']) && $error['title'] !== '') { + $messages[] = $error['title']; + } elseif (isset($error['code'])) { + $messages[] = $error['code']; + } + } + } + return $messages; + } + if (is_object($errors)) { + // Object-shaped envelopes (e.g. { "invalid_aliases": {...} }) carry + // data under arbitrary keys; surface each so it isn't silently + // dropped. Key order is unspecified, so sort for deterministic output. + $messages = []; + foreach (get_object_vars($errors) as $key => $value) { + $rendered = is_string($value) ? $value : json_encode($value); + $messages[] = $key . ': ' . $rendered; + } + sort($messages); + return $messages; + } + return []; + } } diff --git a/lib/Configuration.php b/lib/Configuration.php index b7ee784..af83104 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -14,7 +14,7 @@ * * A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com * - * The version of the OpenAPI document: 5.6.0 + * The version of the OpenAPI document: 5.7.0 * Contact: devrel@onesignal.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.0.0-SNAPSHOT @@ -99,7 +99,7 @@ class Configuration * * @var string */ - protected $userAgent = 'OpenAPI-Generator/5.6.0/PHP'; + protected $userAgent = 'OpenAPI-Generator/5.7.0/PHP'; /** * Debug switch (default set to false) @@ -430,8 +430,8 @@ public static function toDebugReport() $report = 'PHP SDK (onesignal\client) Debug Report:' . PHP_EOL; $report .= ' OS: ' . php_uname() . PHP_EOL; $report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL; - $report .= ' The version of the OpenAPI document: 5.6.0' . PHP_EOL; - $report .= ' SDK Package Version: 5.6.0' . PHP_EOL; + $report .= ' The version of the OpenAPI document: 5.7.0' . PHP_EOL; + $report .= ' SDK Package Version: 5.7.0' . PHP_EOL; $report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL; return $report; diff --git a/lib/HeaderSelector.php b/lib/HeaderSelector.php index b4ecb35..e4d6091 100644 --- a/lib/HeaderSelector.php +++ b/lib/HeaderSelector.php @@ -14,7 +14,7 @@ * * A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com * - * The version of the OpenAPI document: 5.6.0 + * The version of the OpenAPI document: 5.7.0 * Contact: devrel@onesignal.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.0.0-SNAPSHOT diff --git a/lib/ObjectSerializer.php b/lib/ObjectSerializer.php index 29ff4c0..9280335 100644 --- a/lib/ObjectSerializer.php +++ b/lib/ObjectSerializer.php @@ -15,7 +15,7 @@ * * A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com * - * The version of the OpenAPI document: 5.6.0 + * The version of the OpenAPI document: 5.7.0 * Contact: devrel@onesignal.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.0.0-SNAPSHOT diff --git a/lib/OneSignalErrors.php b/lib/OneSignalErrors.php new file mode 100644 index 0000000..ac32c44 --- /dev/null +++ b/lib/OneSignalErrors.php @@ -0,0 +1,31 @@ +