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

[Bug]: home.page.ts:191 POST https://api.onesignal.com/notifications?c=push 400 (Bad Request) #1014

Open
2 of 3 tasks
MalikHamza007 opened this issue Aug 17, 2024 · 0 comments

Comments

@MalikHamza007
Copy link

MalikHamza007 commented Aug 17, 2024

What happened?

I'm working with one signal push notifications in ionic everything is alright i have seen my code the app ids , firebase, rest api keys, api urls everything is alright even my code i have tested it , it works but somehow from in app when i try to send notifications that part doesn't works it simply returns api error 400 (Bad request).

Steps to reproduce?

1. just click on the send notification to all users and or even specific user it will return the error.

What did you expect to happen?

IT should send the notifcations via app also but it doesnt however from the one signal dashboard i am able to do so.

OneSignal Cordova SDK version

Release 11.5.1

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

private calculateDataSize(data:any):number {
    return new Blob([JSON.stringify(data)]).size;

  }
  sendNotification(
    title: string,
    msg: string,
    data: any = null,
    external_id?: string
  ) {
    // checking data  size doesn't exceed more than 2048 bytes
    if(data && this.calculateDataSize(data) > 2048) {
      return throwError(() => Error('Data Payload Exceeds 2048 bytes limit'))
    }
    let body: any = {
      app_id: environment.onesignal.appId,
      name: 'ShipSanitor',
      target_channel: 'push',
      headings: { en: title },
      contents: { en: msg },
      small_icon: 'mipmap/ic_launcher_round',
      large_icon: 'mipmap/ic_launcher_round',
      android_channel_id: environment.onesignal.android_channel_id,
      data: data,

    };
   
    if (external_id) {
      // specific device or deives
      body = {
        ...body,
        include_aliases: {
          external_id: external_id,
        },
      };
    } else {
      body = {
        ...body,
        included_segments: ['Subscribed Users'],
      };
    }
    const headers = new HttpHeaders()
    .set('accept', 'application/json')
    .set('Content-Type', 'application/json')
    .set('Authorization', `Basic ${btoa(environment.onesignal.restAPIKey)}`);
    return this.http.post<any>(
      environment.onesignal.APIUrl,
      body,
      { headers: headers }
    )
   }

Code of Conduct

  • I agree to follow this project's Code of Conduct
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

1 participant