Josh Kahane
Josh Kahane

Reputation: 17169

OneSignal postNotification Failed

I am trying to post a notification to all registered users with OneSignal.

I have a couple of users registered to test with and have successfully sent a notification form the OneSignal website dashboard.

However, when I try the following code, I get the following errors:

[OneSignal postNotification:@{
                             @"contents" : @{ @"en" : @"Test Message" },
                             @"object" : @{ @"en" : @"Test Title" },
                             @"app_id" : @"MY_SECRET_APP_ID",
                             } 
                 onSuccess:^(NSDictionary *result) {

                 } 
                 onFailure:^(NSError *error) {
                     NSLog(@"%@", error.localizedDescription);
                 }];

Error:

Create notification failed and The operation couldn’t be completed. (OneSignalError error 400.)

Upvotes: 2

Views: 2073

Answers (1)

jkasten
jkasten

Reputation: 3948

You must use a targeting parameter, only include_player_ids may be used from your app. All other targeting parameters such as tags or segments must be used from your server through the OneSignal create notification REST API POST call. You can get the current OneSignal user / player id by calling IdsAvailable.

To send a notification to all users from your server you will need to add the following to your JSON

"included_segments": ["All"],

Also note, object isn't a valid key so it will be ignored. I believe you are looking for headings based on the value you have.

Upvotes: 4

Related Questions