user_badges blank?
Hi,
I'm attempting to create a page to show off our Superusers, and I wanted to pull their yearly SU badges to show off how long they've been in the program.
I'm using the API browser in Studio to make sure I've got the right data before coding the next step, but the user_badges data for the users I'm searching is non-existent. The profile I'm viewing has earned 9 badges, so I'm baffled why this is blank.
API call:
SELECT user_badges FROM users WHERE id = '238'
Result:
{
"status" : "success",
"message" : "",
"http_code" : 200,
"data" : {
"type" : "users",
"list_item_type" : "user",
"size" : 1,
"items" : [ {
"type" : "user",
"user_badges" : {
"type" : "user",
"items" : [ ]
}
} ]
},
"metadata" : { }
}v
Appreciate any input on this, am I missing a constraint? Is this a bug? I've checked the documentation and the query seems to be correct. I've even done similar in the past and the query matches what I did there (that code isn't currently live for me to verify if this is just a problem with API Browser or Studio).
Thanks in advance 🙂
Hi Kev, I looked at this one for quite a while. This looks like an API browser issue, as the following API calls return the right data, even without credentials:
- /api/2.0/search?q=SELECT+user_badges+FROM+users+WHERE+id+%3D%27238%27
- /api/2.0/users/238
You may also notice the API browser is showing the collection with type: "user" instead of type: "user_badge".
Could you try putting the query in a simple component? Does the component get the right data when viewed by the user ("Lemmings")? How about other users?
By design, we allow a user to learn about badges they haven't earned yet, but only when viewing their own badges. To make that work, the backend has different approaches for getting the data, depending on who is making the query & where. It's possible there could be an issue in just one of those approaches.