Docs

createPhoneNumber()

Creates a PhoneNumber for the specified user.

function createPhoneNumber: (params: CreatePhoneNumberParams) => Promise<PhoneNumber>;
  • Name
    userId
    Type
    string
    Description

    The ID of the user to create the phone number for.

  • Name
    phoneNumber
    Type
    string
    Description

    The phone number to assign to the specified user. Must adhere to the E.164 format standard for phone number format.

  • Name
    primary?
    Type
    boolean
    Description

    Whether or not to set the phone number as the user's primary phone number. Defaults to false, unless it is the first phone number.

  • Name
    verified?
    Type
    boolean
    Description

    Whether or not the phone number is verified.

  • Name
    reservedForSecondFactor
    Type
    boolean
    Description

    Whether or not the phone number is reserved for multi-factor authentication. The phone number must also be verified. If there are no other reserved second factors, the phone number will be set as the default second factor.

const response = await clerkClient.phoneNumbers.createPhoneNumber({
  userId: "user_123",
  phoneNumber: "15551234567",
  primary: true,
  verified: true
})

console.log(response);
/*
_PhoneNumber {
  id: 'idn_123',
  phoneNumber: '15551234567',
  reservedForSecondFactor: false,
  defaultSecondFactor: false,
  verification: _Verification {
    status: 'verified',
    strategy: 'admin',
    externalVerificationRedirectURL: null,
    attempts: null,
    expireAt: null,
    nonce: null
  },
  linkedTo: []
}
*/

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint POST/phone_numbers. See the BAPI reference for more details.

Feedback

What did you think of this content?