Endpoint Error Using httpGet()

Hi everyone:

I am a new comer to the SmartApp platform. When using httpGet() in a demo, I always encountered an error: java.lang.SecurityException: Endpoint null is blacklisted.

I have done a research over many similar posts here but still cannot figure out why my code is not working. Can you guys help me and provide some guidance?

Thanks so much!

My code:

/**
 *  Make API calls from a SmartApp
 *
 */
definition(
    name: "Make API calls from a SmartApp",
    namespace: "com.smartthings.dev",
    author: "SmartThings Hack",
    description: "Make REST calls inside a SmartApp.",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    oauth: true)


preferences {
    section("Title") {
        // TODO: put inputs here
    }
}

def installed() {
    log.debug "Installed with settings: ${settings}"

    initialize()
}

def updated() {
    log.debug "Updated with settings: ${settings}"

    unsubscribe()
    initialize()
}

def initialize() {

try {
    httpGet(params) { resp ->
        resp.headers.each {
           log.debug "${it.name} : ${it.value}"
        }

        def theHeaders = resp.getHeaders("Content-Length")

        log.debug "response contentType: ${resp.contentType}"
        log.debug "response status code: ${resp.status}"
        log.debug "response data: ${resp.data}"
    }
} catch (e) {
        log.debug "something went wrong: $e"
}

}

def params = [
    uri: "http://httpbin.org",
    path: "/get"
]

Hey,
I believe the issue is that the params object you created is out of scope of the initialize method. The error is stating that the url: null - is blacklisted. You can verify by logging the params object in the initialize method before the http call - which will be null. The easy fix here is to do:

def initialize() {
   def params = [
       uri: "http://httpbin.org",
       path: "/get"
   ]
   try {
       httpGet(params) { resp ->
          resp.headers.each {
           log.debug "${it.name} : ${it.value}"
        }
        def theHeaders = resp.getHeaders("Content-Length")
        log.debug "response contentType: ${resp.contentType}"
        log.debug "response status code: ${resp.status}"
        log.debug "response data: ${resp.data}"
       }
   } catch (e) {
           log.debug "something went wrong: $e"
   }
}
3 Likes

Thanks for your quick help!

Yes! This fix solves my problem.

2 Likes