Search…
Other 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 you backend.

Transactional SMS

Send an SMS to a user after they sign up
1
var client clerk.Client
2
3
func afterSignup(user *clerk.User) error {
4
if user.PrimaryPhoneNumberID == nil {
5
return nil
6
}
7
8
message := clerk.SMSMessage{
9
Message: "Thanks for joining!",
10
PhoneNumberID: *user.PrimaryPhoneNumberID,
11
}
12
13
_, err := hd.client.SMS().Create(message)
14
if err != nil {
15
return err
16
}
17
18
return nil
19
}
Copied!

Update metadata

Add a new key/value to the private metadata stored on a user.
1
var client clerk.Client
2
3
func addStripeCustomerID(user *clerk.User, stripeCustomerID string) error {
4
currPrivMetadata := user.PrivateMetadata.(map[string]interface{})
5
currPrivMetadata["stripe_customer_id"] = stripeCustomerID
6
7
var keyValStrings []string
8
for key, value := range currPrivMetadata {
9
keyValStrings = append(keysString, fmt.Sprintf("\"%s\": \"%s\"", key, value))
10
}
11
finalStr := fmt.Sprintf("{%s}", strings.Join(keysString, ","))
12
user, err := s.clerkClient.Users().Update(sess.UserID, &clerk.UpdateUser{
13
PrivateMetadata: finalStr,
14
})
15
16
if err != nil {
17
panic(err)
18
}
19
}
Copied!
Last modified 1mo ago
Copy link
Edit on GitHub