MissingPropertyException on Clickatell API in grails
NickName:chichacorn93 Ask DateTime:2013-10-12T14:29:28

MissingPropertyException on Clickatell API in grails

I am working on a Web App on grails and I am using Clickatell as the Web API. I have these codes on an SMSNotifier.groovy class. Yet, I encounter the MissingPropertyException

groovy.lang.MissingPropertyException: No such property: POST for class: utils.SMSNotifier at utils.SMSNotifier.sendClickatellSms(SMSNotifier.groovy:54)

The codes which is inside the SMSNotifier class which has errors, are the following:

    def sendClickatellSms(def number, def text) 
    { 
    def http = new HTTPBuilder('http://api.clickatell.com/') 
    http.contentType = TEXT 
    EncoderRegistry encoders = new EncoderRegistry();
    encoders.setCharset('ISO-8859-1') http.setEncoderRegistry(encoders)

    http.request( POST ) 
    { 
    uri.path = 'http://sendmsg' 
    requestContentType = URLENC 
    if (number.substring(0, 1) == '+') 
    { 
    // Remove a leading plus sign number = number.substring(1) 
    } 
    body = [ api_id: '3442677', user: 'iTech013', password: '', from: '+639277705918', to: number, text: text, concat: '3', callback: '2', deliv_ack: '1' ]

    response.success = { resp, reader -> def msg = reader.text if (msg.substring(0, 2) == 'ID') { return 0 } else if (msg.substring(0, 3) == 'ERR') { log.error("Clickatell " + msg) return msg.substring(5, .toInteger() } else { return 1 }

    } response.failure = { resp -> log.error("Failed to contact Clickatell: ${resp.statusLine}") return 1 } } }

The SMSNotifier.groovy file:

package utils

import org.itech.klinikav2.domain.Patient import org.itech.klinikav2.enums.NotificationType;

import groovyx.net.http.EncoderRegistry 
import groovyx.net.http.HTTPBuilder 
import static groovyx.net.http.Method.GET 
import static groovyx.net.http.ContentType.TEXT import grails.persistence.Event

/** * @author Randy * */

class SMSNotifier 
{
//this method is to send a message with a patient parameter and message 
public static String chooseMessage(NotificationType notifType, Patient patient)
{ 
def message= "Greetings! You will have a follow-up appointment tomorrow." def doctor= "Doctor: "   def time= "Time: " 
def p=patient 
if (notifType.equals(NotificationType.FOLLOW_UP_APPOINTMENT))
{ 
message= "Greetings! You will have a follow-up appointment tomorrow." 
return message } 
else if (notifType.equals(NotificationType.BALANCE))
{ 
message= "Greetings! Just reminding you of your balance for appointment payment." 
return message } 
}

def sendToList(ArrayList<Patient> patients, NotificationType notifType)
{ 
def patientList= patients for (int i=0; i< patientList.size(); i++)
{ def patient = patientList.get(i) 
def message = chooseMessage(notifType, patient) 
sendClickatellSms(patient.mobileNumber, message) } 
}

def sendClickatellSms(def number, def text) 
{ 
def http = new HTTPBuilder('http://api.clickatell.com/') 
http.contentType = TEXT EncoderRegistry encoders = new EncoderRegistry();      
encoders.setCharset('ISO-8859-1') http.setEncoderRegistry(encoders)

http.request(POST)
{ 
uri.path = 'http://sendmsg' 
requestContentType = URLENC 
if (number.substring(0, 1) == '+') 
{ // Remove a leading plus sign 
number = number.substring(1) 
} 
body = [ api_id: '3442677', user: 'iTech013', password: 'ingenium123..', from: '+639277705918', to: number, text: text, concat: '3', callback: '2', deliv_ack: '1' ]

response.success = 
{ resp, reader -> def msg = reader.text if (msg.substring(0, 2) == 'ID') { return 0 } 
else if (msg.substring(0, 3) == 'ERR')
{ 
log.error("Clickatell " + msg) 
return msg.substring(5, .toInteger() } 
else { return 1 }

} 
response.failure = { resp -> log.error("Failed to contact Clickatell: ${resp.statusLine}") return 1 } } }

}

I called this method through the index() method of a Controller class. These are the codes:

    def index() 
    { 
    def sms = new SMSNotifier() 
    def result= sms.sendClickatellSms("09277705918", "Hi!") 
    if(result==1) { render "success" } 
    else{ render "sorry" } 
    }

I left the password space blank, but i put the actual password on my actual codes.

I think the answer is simple, I am just starting with APIs so, every bit of knowledge and help on this matter is highly appreciated! Thank you in advance! :)

Copyright Notice:Content Author:「chichacorn93」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19331287/missingpropertyexception-on-clickatell-api-in-grails

More about “MissingPropertyException on Clickatell API in grails” related questions

MissingPropertyException on Clickatell API in grails

I am working on a Web App on grails and I am using Clickatell as the Web API. I have these codes on an SMSNotifier.groovy class. Yet, I encounter the MissingPropertyException groovy.lang.

Show Detail

Invalid or missing api_id in clickatell

i am trying to integrate clickatell SMS gateway in my web system. i make free test account on clickatell and create SMS REST integrations , from SMS REST integrations i get API key , am use this a...

Show Detail

MissingPropertyException in grails

I have a problem when I try to show the view of one of my domains. I built a method to sum some quantities, but I have this error and I don't know how to fix it. I understand that the variable awards

Show Detail

Clickatell Connect API - No XML Data found

I'm trying to use Clickatell's Connect API ( http://www.clickatell.com/downloads/Clickatell_Connect_API_User_Guide.pdf?cid=205655 ) in order to create users and send sms. Clickatell's API provides ...

Show Detail

Routing error with REST API in Clickatell

I am trying to send a SMS using REST API in clickatell. I tested it using POSTMAN. I sent the Headers as POST /rest/message HTTP/1.1 Host: api.clickatell.com Accept: application/json Content-Type:

Show Detail

Is it possible to add a FROM to SMS with new clickatell API?

The new platform API at Clickatell seems to not allow you to add "from" to the JSON payload, complaining that it not a 2 way integration, but the is no possibility to add a text moniker to the short

Show Detail

Clickatell SMSes with special GSM characters through REST API

I am using the Clickatell REST API for sending SMSes. I need to send some special characters (like Ä) which are all available in the GSM 03.38 standard (and in latin-1 as well). So, I don't want to...

Show Detail

Grails MissingPropertyException

I've been getting a strange error that has had me hung up all morning. I have a Grails application with a Person class that looks like this: class Person { String id Date lastUpdated...

Show Detail

Clickatell - WhatsApp Template - One API

I try to send a WhatsApp template message using the Clickatell One API end point. Here is my payload. I'm send this against the endpoint with POST. { &quot;messages&quot;:[ { ...

Show Detail

Intellij 12.1.6 (Community), Creating Grails project, Caught: groovy.lang.MissingPropertyException: No such property: grails for class: BuildConfig

I was following this tutorial to create grails (version 2.3.1) application. I am not using Maven and instead of MongoDb i'm using postgresql, but I believe these changes are not the things to be

Show Detail