JSON Transformation Help needed

I’m on OH2
Which variable are you talking about?

The fuel variable could you please post if you are using OH1 or 2 and your imports.

Thanks
Thomas

As stated above I’m using OH2. The only relevant import is JSON Transformation Service(IMHO).

I do pass the number I got from the json ( either E10, E5 or Diesel ) to the relevant (number)item as a string. Why? I don’t remember, but it works that way. It gets displayed on the sitemap and it gets persisted correctly in the Database.

Currently i have the problem that the transform statement throws an exception and i dont know why.

Thomas

Could you please share an example of the modified tankerkoenig rule?
@Dibbler42 or @opus

The detail.php does not work at the moment.

For the prices I’m not using detail, a permanent call to detail is not necessary! Prices should be called with the “prices” scrpt.
What kind of problems do you have with the “details” script? Error messages and code used would be helpfull.

Here my price code:

val String Tankstelle1_ID=“3e563b17-f3fc-4a3d-b486-60d25e5948d5”
val String Tankstelle2_ID=“bc01b1b9-b2b9-4f78-98ef-b7ee8d8a66a4”
val String Tankstelle3_ID=“a53fff71-133c-48b1-84ba-20a9be6ec538”
val String API_Key=“myAPIKey”
var String Status
var Number E10
var Number E5
var Number Diesel
var String TankstellenMarke
var String TankstellenStrasse
var String TankstellenOrt

rule “Benzinpreise”
when
Time cron “50 7,17,27,37,47,57 * * * ?”
then
var String URL= “https://creativecommons.tankerkoenig.de/json/prices.php?ids=” + Tankstelle1_ID + “,” +Tankstelle2_ID + “,” + Tankstelle3_ID + “&apikey=” + API_Key
logInfo (“Benzinpreise”, “URL = {}”, URL)
var String json = sendHttpGetRequest(URL)
var Number PreisGeschlossen=0
logInfo(“Benzinpreise”,“JSON-String = {}”, json)
if (json!=null) {
var Boolean OK = transform(“JSONPATH”, “$.ok”, json)
if (OK=true) {
Status = transform(“JSONPATH”, “$.prices.” + Tankstelle1_ID + “.status”, json)
//logInfo(“Benzinpreise”, “Status = {}”, Status)
if (Status==“open”) {
E10 = transform(“JSONPATH”, “$.prices.” + Tankstelle1_ID + “.e10”, json)
E5 = transform(“JSONPATH”, “$.prices.” + Tankstelle1_ID + “.e5”, json)
Diesel = transform(“JSONPATH”, “$.prices.” + Tankstelle1_ID + “.diesel”, json)
E10_1.postUpdate(E10.toString)
E5_1.postUpdate(E5.toString)
Diesel_1.postUpdate(Diesel.toString)
}
else {
}
Status = transform(“JSONPATH”, “$.prices.” + Tankstelle2_ID + “.status”, json)
if (Status==“open”) {
E10 = transform(“JSONPATH”, “$.prices.” + Tankstelle2_ID + “.e10”, json)
E5 = transform(“JSONPATH”, “$.prices.” + Tankstelle2_ID + “.e5”, json)
Diesel = transform(“JSONPATH”, “$.prices.” + Tankstelle2_ID + “.diesel”, json)
E10_2.postUpdate(E10.toString)
E5_2.postUpdate(E5.toString)
Diesel_2.postUpdate(Diesel.toString)
}
else {

        }
        Status = transform("JSONPATH", "$.prices." + Tankstelle3_ID + ".status", json)
        if(Status=="open") {
            E10 = transform("JSONPATH",  "$.prices." + Tankstelle3_ID + ".e10", json)
            E5  = transform("JSONPATH",  "$.prices." + Tankstelle3_ID + ".e5", json)
            Diesel  = transform("JSONPATH",  "$.prices." + Tankstelle3_ID + ".diesel", json)
            E10_3.postUpdate(E10.toString)
            E5_3.postUpdate(E5.toString)
            Diesel_3.postUpdate(Diesel.toString)
        }
        else {
         }
    }
    else {
        logInfo("Benzinpreise", "OK = {}", OK)
        var String HttpError = transform("JSONPATH",  "$.message", json)
        logInfo("Benzinpreise", "HttpError = {}", HttpError)
    }
}    
else {
    logInfo("Benzinpreise", "Empty Return from HTTPRequest")        
}

end

1 Like