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

Pushing to 'ios' channel gives "Parse::ParseProtocolError: 115: Can't set channels for a query-targeted push." #172

Closed
jasonschock opened this issue Jun 17, 2015 · 1 comment · Fixed by #179
Assignees
Labels

Comments

@jasonschock
Copy link

Just attempting a simple push via Parse. This is almost straight from the README.

Gemfile:

gem 'parse-ruby-client', git: 'git://github.com/adelevie/parse-ruby-client.git'

Commit SHA is cac0493.


This returns an error:

parse = Parse.create(
    application_id: ENV['parse_application_id'],
    api_key: ENV['parse_api_key'],
    quiet: false)

push = parse.push({alert: 'Hello.'}, 'user_e3929e0df56e163acc3072df2b2748')

push.type='ios'

push.save

Response:

I, [2015-06-17T13:47:18.870459 #9008]  INFO -- : post https://api.parse.com/1/push
I, [2015-06-17T13:47:19.329457 #9008]  INFO -- Status: 400
Parse::ParseProtocolError: 115: Can't set channels for a query-targeted push.
from /opt/boxen/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/parse-ruby-client-cac04938900c/lib/faraday/extended_parse_json.rb:25:in `process_response'

This works fine:

push = parse.push({alert: 'Hello.'}, 'user_e3929e0df56e163acc3072df2b2748')
# Don't set the type
push.save

Response:

I, [2015-06-17T13:53:29.577909 #9008]  INFO -- : post https://api.parse.com/1/push
I, [2015-06-17T13:53:30.024296 #9008]  INFO -- Status: 200
=> {"result"=>true}

Sorry, but what am I missing, or this a bug?

@rhymes
Copy link
Contributor

rhymes commented Jun 18, 2015

@jasonschock that's because you can't set the channel and the device type at the same time. See https://parse.com/questions/cant-set-channels-for-a-query-targeted-push - According to Parse you can either set a channel with the second argument as you did or set the device type (which act as a filter). If you want to set a channel AND the device type you have to use two strategies as the current library API goes:

1 - set push.channels instead of push.channel (it's confusing I know)

push = parse.push({alert: 'Hello.'})
push.channels = ['user_e3929e0df56e163acc3072df2b2748']
push.where = {deviceType: 'ios'}

Though I think like this it will send the push only to the devices that have only that channels set and not the devices that have that channels and optionally others.

2 - use the where all the way (my suggestion)

push = parse.push({alert: 'Hello.'})
push.where = {deviceType: 'ios', channels: { '$in': ['user_e3929e0df56e163acc3072df2b2748']}
push.save

@Xavdidtheshadow I think the mechanism @channel / @channels needs some love and this seems a bug to me https://github.com/adelevie/parse-ruby-client/blob/master/lib/parse/push.rb#L46 (the where clause doesn't need a where key, just the conditions)

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

Successfully merging a pull request may close this issue.

3 participants