HTTP Get Json

I am building a driver for a device, that needs to get the setup from a webservice, in a json format.

I am doing all the HTTP Get, Json Parser, and getting everything as I read in the posts, history, old issues with HTTP get and jsson - but still can't figure out what might be going on.

The result.data = already comes in a broken version, not json.
If you do the http link directly via browser, the json is properly formatted.
While when you do the http get via driver, it already comes broken.

I recompiled a small version of the driver, here below, with only the functions needed to do the HTTP.

1- The link for the webservice with the json return:
https://molsmart-integration.web.app/controle-integration?token=eyJhbGciOiJIUzI1NiJ9.eyJpZCI6OSwibmFtZSI6IlNhbXN1bmcgTW9kZWxvIDEgKGNhc2EgcmFwaGEpIiwicHJpdmF0ZSI6dHJ1ZSwidXNlcl9pZCI6NH0.ONe1pZOrDMb4SGfJWOIl7WCtsz7a_pguAS4Ug0ERqVE

2- This is the part of the code for the http below:

def parseJson(resp)
{
    def jsonSlurper = new groovy.json.JsonSlurper()
    try
    {
        resp_json = jsonSlurper.parseText(resp.toString())        
        return resp_json
    }
    catch (Exception e)
    {
        log.warn "parse failed: ${e.message}"
        return null
    }
}
def httpGetExec()
{
    logDebug("httpGetExec()") 
    try
    {       
        httpGet(webserviceurl) 
        { resp ->
            if (resp.data)
            {
                logDebug("resp.data = ${resp.data}")
                return resp.data
            }
        }
    }
    catch (Exception e)
    {
        logDebug("httpGetExec() failed: ${e.message}")
    }
}

These are the logs: As you can see the result.data is already wrong formatted without "{"

And here the clean response json in browser.

Any ideas ? Thanks!!!

1 Like

An important piece of information that would be helpful but I see missing is how you're constructing the webserviceurl object. (For example, it's possible some services will work better if you specify a return content type.)

That being said, the data you're getting back appears to already be a parsed Map containing the JSON data, unless I'm missing something (perhaps because of one the options you specified that we can't see--I think this is normally a raw string; I normally use the json property instead of the data property without this when this is what I'm expecting). Have you tried just working with that object directly? In any case, no manual slurping should be needed.

Hi @bertabcd1234 !! Thanks for the update.

Followed your advise of working directly and worked.

Thanks for the help.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.