Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide example how to retrieve and update public/private/unsafe metadata #30

Open
d-stoll opened this issue Oct 5, 2024 · 0 comments

Comments

@d-stoll
Copy link

d-stoll commented Oct 5, 2024

Hi Clerk-Team,

nice to see that you are working on a Java SDK for the clerk backend! Really eager to replace our internal clerk library with this project.

However, I encountered the following issue:

When retrieving the details of a user, the public metadata (as well as unsafe and private metadata) just returns an object of an empty wrapper class. Do I have to subclass or parse the metadata somehow to get a usable object?

Here is an example:

package hello.world;

import com.clerk.backend_api.Clerk;
import com.clerk.backend_api.models.operations.GetUserResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {
        try {
            Clerk sdk = Clerk.builder()
                .bearerAuth("<YOUR_BEARER_TOKEN_HERE>")
                .build();

            GetUserResponse res = sdk.users().get()
                .userId("<value>")
                .call();

            if (res.user().isPresent()) {
                var user = res.user().get();
                
                if (user.publicMetadata().isPresent()) {
                  // This is just an empty object with no methods
                   var publicMetadata = user.publicMetadata().get();

                   // What do I have to do here to get the actual metadata?
                }
            }
        } catch (Exception e) {
            throw e;
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant