remote api script for coldfusion

Answered

Comments

10 comments

  • Avatar
    Gary Fenton

    I'm at the same stage as you. I know you need to use cfhttp to post the json request to the api but this isn't working for me yet. The problem might be using https and the underlying Java engine needs the Pushwoosh SSL cert copied into its keystore.

    What version of CF do you use? I'm on 8.01. Newer versions like 10 onwards might automatically handle the https issue.

    The alternative method is to use cfexecute and run CURL. But I'd prefer to focus on cfhttp first.

  • Avatar
    Gary Fenton

    Sorry, I should have posted this as a comment because this is not a proper answer, it's merely some guidance.

  • Avatar
    Gary Fenton

    Here's the CFML for using the PW API:

    < cfhttp url="http://cp.pushwoosh.com/json/1.3/createMessage"
    port="80"
    method="post"
    timeout="20"
    >
    < cfhttpparam type="header" name="Content-type" value="application/json">
    < cfhttpparam type="body" value="#jsonReq#">
    < /cfhttp>
    

    A couple of things to note. For older versions of CF use port 80, otherwise try using port 443 and use https in the URL.

    The var jsonReq should contain your JSON call to the API.

    e.g.

    < cfset jsonReq='{
        "request": {
            "application": "your PW application ID goes here",
            "auth": "your PW API auth key goes here",
            "notifications": [{
            "send_date": "now",
            "ignore_user_timezone": true,
            "content": "Hello world"
            }]
        }
    }'>
    

    To check the response from the PW server:

     < cfdump var="#cfhttp#" label="cfhttp">
    
  • Avatar
    Claude Raiola

    Well Done Garry it works a treat !!!!!

  • Avatar
    Claude Raiola

    Hi

    At moment i have pushwosh working well with my cf app each time i run a process in my coldfusion developed system to send a push alert it sends perfectly even when i run a scheduled task etc sending to my appid hard coded into the cfcode

    Now i need to be able to dynamically send to specific users. I know i need to identify the app registration id each time an app is opened dynamically and use that value when creating the ios channel

    do you have any advise on how i take the app to the next level now that i have it working as expected to my hard coded app id

  • Avatar
    Gary Fenton

    The answer is documented: http://docs.pushwoosh.com/docs/createmessage

    You need to use the "devices" parameter and include an array of device IDs that you want to receive your PN.

  • Avatar
    Claude Raiola

    Hi Gary

    I assume thats how i populate the device id's that need to be sent the outbound message.

    I would populate that value form the cfm page was the user / or a query will determine which user needs to have the message sent to their respective apps "i think i am across that"

    my question is how do i capture the ids at the time the app is downloaded and installed (where i assume the device is determined ???) so that i can then store that value in my sqldbase against the specifc app users profile ???

    am i on the right page ???

    I am also told the device ID can potentially change after a reboot or device reset of the device is that correct from your experience and if so the device id needs to be re confirmed and sent to my system and updated each time the app opens in case there has been a device id change ????

    separate note, i am really amazed at the lack of support replies in the community for all support posts many posts have plenty of people who view the post but majority of posts do not seem to have any replies, does not say a great deal about "community suppot" by the pushwoosh community

    looking forward to the reply

  • Avatar
    Gary Fenton

    The device ID used by Pushwoosh (and probably others) appears to be exactly the same as the one you'll get from the Cordova method device.uuid. After your app has initiated you could send the device.uuid to your server's database to build your list of client device IDs.

  • Avatar
    Claude Raiola

    Hi Gary i am using following code found on corodva docs to try and get the deviceUUID

    however the output on my iphne when i run this script is "Loading device properties"

    all i am trying to do is find the code so i can output UUID and then use it in my app each time the app loads

    <html> <head> <title>Device Properties Example</title>
        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
        <script type="text/javascript" charset="utf-8">
    
            // Wait for device API libraries to load
            //
            document.addEventListener("deviceready", onDeviceReady, false);
    
            // device APIs are available
            //
            function onDeviceReady() {
                var element = document.getElementById('deviceProperties');
                element.innerHTML = 'Device Model: '    + device.model    + '<br />' +
                'Device Cordova: '  + device.cordova  + '<br />' +
                'Device Platform: ' + device.platform + '<br />' +
                'Device UUID: '     + device.uuid     + '<br />' +
                'Device Version: '  + device.version  + '<br />';
            }
    
            </script>
    </head>
    <body>
        <p id="deviceProperties">Loading device properties...</p>
    </body>
    

    </html>

  • Avatar
    Gary Fenton

    Are you using PhoneGap Build to create an ipa file and then installing the app onto your iPhone? If so then delete the line of code that calls cordova.js because PGB will automatically insert it.

    Or are you copying an HTML file onto your iPhone and opening it in Safari? This won't work, you need to upload your files (complete with config.xml) to PGB and get it to build an ipa file.

Please sign in to leave a comment.