I am still struggling with navigating the user_badges return data and wondered if Kev_B could maybe share some of the code where he got it working.
So I tried via the API browser to query SELECT user_badges FROM users WHERE id = '65' and got
{
"status" : "success",
"message" : "",
"http_code" : 200,
"data" : {
"type" : "users",
"list_item_type" : "user",
"size" : 1,
"items" : [ {
"type" : "user",
"user_badges" : {
"type" : "user",
"items" : [ ]
}
} ]
},
"metadata" : { }
}
Which seems to follow the issue AndrewF described about API browser returning incomplete results.
So I built my component like this
<#assign allbadges = restBuilder().liql("SELECT user_badges FROM users WHERE id = '${(page.context.user.id)!'65'}'") />
<#list allbadges.data.items as badge>
${badge}
</#list>
This returns a nice 😐 object output of with a map of an empty user and a user_badges map one level down
InMemoryObjectInstanceTemplateModel{entity=InMemoryObjectInstance [fieldMap={type=user, user_badges=InMemoryObjectInstance [fieldMap={size=26, list_item_type=user_badge, items=[InMemoryObjectInstance [fieldMap={badge=InMemoryObjectInstance [fieldMap={icon_url=https://community.stage.dataiku.com/html/@6B716363DFAD3E73EB8A75D5A60C9A35/badge_icons/Public%20Alpha%20Tester.png, awarded=58, activation_date=Wed Oct 23 08:32:18 PDT 2019, description=Thank you for your feedback and participating in our Alpha Test!, id=14, type=badge, title=Alpha Test}.....
As soon as I try to list through that user_badges collection by amending the code to
<#list allbadges.data.items.user_badges as badge>
all hell breaks loose and I only get a fat freemarker error that just shouts "Claudius, you don't understand what Freemarker sequences are":
For "." left-hand operand: Expected a hash, but this has evaluated to a sequence (com.google.common.collect.Lists$TransformingRandomAccessList wrapped into f.t.DefaultListAdapter):
==> allbadges.data.items [in template "preview" at line 10, column 12]
I tried already to go list out user and user_badges separately by
<#list allbadges.data.items[0] as user, user_badges>
But that didn't get me much further either.
Can someone help me on the right track to get a list of user badges from a LiQL call on the user collection?