boboldehampsink / pushnotifications

DEPRECATED - Push Notifications (iOS/Android) plugin for Craft CMS
MIT License
21 stars 6 forks source link

How to add a new device via Android/iOS application instead of through the CP? #1

Closed sandy-abrightmind closed 8 years ago

sandy-abrightmind commented 8 years ago

Hi

I've been trying to figure out how to add a new device token to an app via Android/iOS code instead of through the CraftCMS CP?

Can I add a new device token via URL?

If so, what is an example URL with the POST parameters?

Thanks! Sandy Davis

boboldehampsink commented 8 years ago

You have to POST to actions/pushNotifications/registerDevice with:

{
    'app': 'app_handle',
    'platform': 'ios/android',
    'registrationId': 'token'
}

P.s. send these as POST params, not as JSON ;-)

sandy-abrightmind commented 8 years ago

I'm still not doing something right. =(I'm testing via Postman.Is the correct URL: localhost/CraftCMS/public/admin/actions/pushNotifications/registerDevice ?I've attached a screenshot of my postman configuration.Thanks!SandyOn October 15, 2015 at 8:21 AM Bob Olde Hampsink notifications@github.com wrote:You have to POST to actions/pushNotifications/registerDevice with:{ 'app': 'app_handle', 'platform': 'ios/android', 'registrationId': 'token' }P.s. send these as POST params, not as JSON ;-)—Reply to this email directly or view it on GitHub.  

boboldehampsink commented 8 years ago

Sorry, I didn't get the screenshot

sandy-abrightmind commented 8 years ago

Yeah, I just realized that it didn't send it via the email. Here it is. postman_config_post

boboldehampsink commented 8 years ago

Ah, you're sending them as Headers instead of as Post values

sandy-abrightmind commented 8 years ago

Oops.

I added them as params and it still doesn't work. =(

If I type the url that it created into an address bar, it gives me "Page Not Found" error... so maybe it's the URL that I have wrong?

post_man_config_2

boboldehampsink commented 8 years ago

Yeah sorry, the url should be /actions/pushNotifications/devices/registerDevice

sandy-abrightmind commented 8 years ago

It works if I submit the URL to the browser but it doesn't add a new device if I do it from postman.

http://localhost/CraftCMS/public/admin/actions/pushNotifications/devices/registerDevice?app=gcm&platform=android&registrationId=test9823

Any ideas why it won't work from postman?

I'm assuming that I won't run into any authentication problems when I try to submit it from my Android/iOS code?

boboldehampsink commented 8 years ago

Because you have the variables both in the url and in the post body?

sandy-abrightmind commented 8 years ago

I don't understand what you mean by that. I have postman configured with the exact same url as above and it doesn't work. I was just curious if that's because it doesn't know the login credentials for CraftCMS. And maybe in the browser, the credentials are cached?

boboldehampsink commented 8 years ago

No, the call can always be made anonymously.

Your url should not have "?app=gcm&platform=android&registrationId=test9823" in it, these should be POSTed

sandy-abrightmind commented 8 years ago

It did that automatically when I set the params in Postman.

When I ran my url in the browser, it returned success as true for that url.

And it added the new device token to Craft when I ran that url in the browser.

However, if I run it via Postman, it does not add the new device token.

boboldehampsink commented 8 years ago

It only does that automatically when you've selected GET instead of POST

sandy-abrightmind commented 8 years ago

Here is a screenshot of my postman configuration.

I have it selected as POST and it still adds the params to the URL.

post_man_params_configuration

boboldehampsink commented 8 years ago

Ok, looks like you're posting with get variables, but empty post body. Can you look inside the Body tab?

sandy-abrightmind commented 8 years ago

The body tab was empty.

Even when I add the information there, it doesn't work in Postman.

sandy-abrightmind commented 8 years ago

Okay, so if I log out of CraftCMS then the URL that worked in the browser doesn't work. It takes me to the login page of craft. =(

sandy-abrightmind commented 8 years ago

I figured it out!!!

It was my URL. Here is a new screenshot:

post-man_config_successful

Thank you for your help! =)

boboldehampsink commented 8 years ago

Nice! That was actually what I was trying to say ;-)

sandy-abrightmind commented 8 years ago

Yeah, I'm new to CraftCMS so I wasn't sure how to access it. =) Thank you for all of your help!!