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

doc: Mark Users.GetPending as deprecated #118

Merged
merged 2 commits into from
May 5, 2023

Conversation

jeremy-stytch
Copy link
Contributor

@jeremy-stytch jeremy-stytch commented May 4, 2023

With the Users Search endpoint, you can get all of your pending users by adding a Status: "pending" filter. This can replace any and all existing calls to the Get Pending Users endpoint.

The Search method also supports more filters to further constrain results. This library also provides a SearchAll convenience helper for iterating through all the results of a search.

We'd like to remove the GetPending method from this library to limit our maintenance work and remove some complexity for customers.

This marks the GetPending method as deprecated. It will be removed in the next major version of stytch-go.

Migration Guide

This migrates from GetPending to SearchAll, which has a cleaner iteration pattern:

Before

ctx := context.TODO()

params := &b2c.UsersGetPendingParams{
    Limit: 200,
}

res, err := client.Users.GetPending(ctx, params)
if err != nil {
	panic(err)
}

// TODO: Do something with res.Users

for res.HasMore {
	params.StartingAfterID = res.StartingAfterID

	res, err = client.Users.GetPending(ctx, params)
	if err != nil {
		panic(err)
	}

	// TODO: Do something with res.Users
}

After

ctx := context.TODO()

params := &b2c.UsersSearchParams{
    Limit: 200,
	Query: &b2c.UsersSearchQuery{
		Operator: b2c.UserSearchOperatorOR,
		Operands: []json.Marshaler{
			b2c.UsersSearchQueryStatusFilter{Status: "pending"},
		},
	},
}

pendingUsers := client.Users.SearchAll(params)

for pendingUsers.HasNext() {
	users, err := pendingUsers.Next(ctx)
	if err != nil {
		panic(err)
	}

	// TODO: Do something with users
}

If you prefer to keep the same iteration pattern that GetPending has, use Search directly instead:

ctx := context.TODO()

params := &b2c.UsersSearchParams{
    Limit: 200,
	Query: &b2c.UsersSearchQuery{
		Operator: b2c.UserSearchOperatorOR,
		Operands: []json.Marshaler{
			b2c.UsersSearchQueryStatusFilter{Status: "pending"},
		},
	},
}

res, err := client.Users.Search(ctx, params)
if err != nil {
	panic(err)
}

// TODO: Do something with res.Results

for res.ResultsMetadata.NextCursor != "" {
	params.Cursor = res.ResultsMetadata.NextCursor

	res, err = client.Users.Search(ctx, params)
	if err != nil {
		panic(err)
	}

	// TODO: Do something with res.Results
}

@jeremy-stytch jeremy-stytch requested a review from a team as a code owner May 4, 2023 20:25
@jeremy-stytch jeremy-stytch merged commit 2644ce4 into main May 5, 2023
@jeremy-stytch jeremy-stytch deleted the jeremy-deprecate-get-pending-users branch May 5, 2023 20:16
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

Successfully merging this pull request may close these issues.

2 participants