Skip to content

Issue: 403 Forbidden Error When Sending Notification via OneSignal #195

@arsarsars1

Description

@arsarsars1

Description:

I am encountering a 403 Forbidden error when attempting to send a notification using the OneSignal::sendNotificationToUser function in Laravel. The error message suggests that the request is being denied due to a missing or invalid API key in the Authorization header. Below is the error message from the exception:

Client error: `POST https://onesignal.com/api/v1/notifications` resulted in a `403 Forbidden` response:
{"errors": ["Access denied. Please include an 'Authorization: Basic ...' header with a valid API key"]}

Code Example:

Here’s the code I’m using to send the notification:

try {
    OneSignal::sendNotificationToUser(
        $message,
        $player_id,
        $url = null,
        $data = null,
        $buttons = null,
        $schedule = null
    );
} catch (\Exception $e) {
    return response()->json([
        "error" => 'one_signal_error',
        "message" => $e->getMessage(),
        "file" => $e->getFile(),
        "line" => $e->getLine(),
    ], 422);
}

Error Message:

{
    "error": "one_signal_error",
    "message": "Client error: `POST https://onesignal.com/api/v1/notifications` resulted in a `403 Forbidden` response:\n{\"errors\": [\"Access denied.  Please include an 'Authorization: Basic ...' header with a valid API key (https:\/\/documenta (truncated...)\n",
    "file": "/home/arloponc/public_html/developer/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php",
    "line": 113
}

Expected Behavior:

The notification should be sent successfully when the correct OneSignal API key is used.

Actual Behavior:

The request results in a 403 Forbidden response, indicating that the API key is either missing or invalid. I have already verified the API key and added it to the environment variables, but the issue persists.

Steps to Reproduce:

  1. Set up the OneSignal integration as per the package instructions.
  2. Use the sendNotificationToUser function to send a notification.
  3. Observe the 403 Forbidden error in the response.

Environment:

  • Laravel Version: 10.48.16
  • PHP Version: 8.1
  • OneSignal Package Version: 2.1 (berkayk/onesignal-laravel)
  • Guzzle Version: 7.2 (guzzlehttp/guzzle)

Additional Information:

  • The API key is set in the .env file, and I'm confident that it's correctly configured.
  • It appears the Authorization header isn't being properly included in the request. However, this seems to be handled internally by the package, so I'm unsure why it's failing.

Any guidance or suggestions would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions