Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arsarsars1 opened this issue Sep 21, 2024 · 4 comments
Open

Comments

@arsarsars1
Copy link

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.

@kaioken
Copy link

kaioken commented Sep 23, 2024

@arsarsars1 hey , I've just used the package make sure your keys are correct , that may be the cause of the issue

@arsarsars1
Copy link
Author

@kaioken I am using the right keys but i don't know where can I pass the auth key.

@mass5
Copy link
Contributor

mass5 commented Dec 30, 2024

@mass5
Copy link
Contributor

mass5 commented Dec 30, 2024

I just pushed a PR to update the new URL for rich keys:
#197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants