Issue with Custom Macro to Display Favorite Spaces — Shows All Users' Spaces Instead

Hi everyone,

I’m working on a custom user macro for Confluence (Data Center) that displays a user’s favorite spaces. I’m using the following API endpoint within an AP.request() call:
/rest/api/user/favourite/space?limit=1000&expand=space.homepage
The macro is intended to display only the current user’s personal favorite spaces, but instead, it returns a list of spaces that belong to various other users, as shown in the screenshot below:


Here’s a snippet of the JavaScript logic I’m using inside the macro:

Favorite Spaces

Loading...

    What I’ve Tried:

    • Double-checked my user’s personal space is marked as a favorite.
    • Verified the macro runs in the correct context.
    • Checked if authentication or impersonation is affecting the result (no obvious issues so far).

    Question:

    Is there a way to ensure the API returns only the favorite spaces of the currently logged-in user? Or is this a known limitation of using this REST API within user macros?

    Any insights or alternative approaches would be appreciated!

    Thanks in advance
    – Vinay