Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev

Examples

Below is a code snippet showing what you can do from your backend with Clerk. Look at the API reference for a full list of requests you can make from your backend.

Update metadata

Add a new key/value to the private metadata stored on a user.

var client clerk.Client func addStripeCustomerID(user *clerk.User, stripeCustomerID string) error { currPrivMetadata := user.PrivateMetadata.(map[string]interface{}) currPrivMetadata["stripe_customer_id"] = stripeCustomerID var keyValStrings []string for key, value := range currPrivMetadata { keyValStrings = append(keysString, fmt.Sprintf("\"%s\": \"%s\"", key, value)) } finalStr := fmt.Sprintf("{%s}", strings.Join(keysString, ",")) user, err := s.clerkClient.Users().Update(sess.UserID, &clerk.UpdateUser{ PrivateMetadata: finalStr, }) if err != nil { panic(err) } }

What did you think of this content?

Clerk © 2023