I have a card with a tree view on it that I'm successfully filling with the data I want pulled from an API - Yay! Now, I want to use a property of "online" from the data I pull, to set the text of that associated line in the tree view to either bold, or a different color, or something to make those lines stand out better.
Here's the code I have so far:
Code: Select all
on openCard
-- set the headers for the API call
set the httpHeaders to "authorization: bearer <myAPIToken>"
put "https://my.zerotier.com/api/network" into tUrl
get url tUrl
-- deal with return data - which works the way I have it here, but it seems wrong since the result isn't empty..but anyway
if the result is empty then
put it into tJSON
put JSONtoArray(tJSON) into tArray
repeat with x = 1 to the number of elements in tArray
-- use the returned ID for each network to call and get the machine members of the network
put tArray[x]["config"]["id"] into tId
set the httpHeaders to "authorization: bearer <myAPIToken>"
put "https://my.zerotier.com/api/network/" & tId & "/member" into t2Url
get url t2Url
if the result is empty then
put it into t2JSON
put JSONtoArray(t2JSON) into t2Array
repeat with y = 1 to the number of elements in t2Array
put t2Array[y]["config"]["ipAssignments"][1] into tIp
put tArray[x]["config"]["name"] into tNetName
put t2Array[y]["name"] into tMachName
if t2Array[y]["online"] = true then
-- do something here to set bold or text color?
-- So far when I do something here, it gives me an error below where I'm actually adding the data to the trer view.
end if
put tIp into temp[tNetName][tMachname]
end repeat
else
answer "Something went wrong."
end if
end repeat
set the sortType of widget 1 to "text"
set the showseparator of widget 1 to true
set the sortOrder of widget 1 to "ascending"
set the arraydata of widget 1 to temp
else
put "Something weird happened here!" into Output
end if
end openCard