Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev

Examples

Below are some various code snippets of 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.

Transactional SMS

Send an SMS to a user after they sign up.

var client clerk.Client func afterSignup(user *clerk.User) error { if user.PrimaryPhoneNumberID == nil { return nil } message := clerk.SMSMessage{ Message: "Thanks for joining!", PhoneNumberID: *user.PrimaryPhoneNumberID, } _, err := hd.client.SMS().Create(message) if err != nil { return err } return nil }

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