Skip to content

Add support for deleting phone-numbers or emails #520

@bendiknesbo

Description

@bendiknesbo

Checklist

Describe the problem you'd like to have solved

With the recent addition of Connection Attributes, we would like to make a call to Management API to delete a user's phone-number or email. We can do that by sending a PATCH call to the users-endpoint (https://auth0.com/docs/api/management/v2/users/patch-users-by-id), with the payload {"phone_number":null} or {"email":null}.

However, there is no way to achieve this when using the Auth0 Go SDK, by using the function User.Update, since passing in a management.User with Email or PhoneNumber set to nil will marshal the struct to {}, which will not delete the phone/email.

Describe the ideal solution

Some suggestions:

  • The management.User could be changed/extended to allow explicit null in the User.Update-call
  • User.Update could take an option (e.g. option.DeletePhoneNumber(), option.DeleteEmail()) that would set the correct payload.
  • A separate User.DeletePhone and User.DeleteEmail (and User.DeleteUsername also?) could be added, which would send the required payload.

Alternatives and current workarounds

A workaround is to use NewRequest and pass a payload that overrides the default Go marshalling, like:

type deletePhoneRequest struct{}
func (r deletePhoneRequest) MarshalJSON() ([]byte, error) {
	return []byte(`{"phone_number":null}`), nil
}

This requires us to manually handle the path to the PATCH-endpoint, and handling the status-code and closing of body, etc. manually.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions