Generate OTP

Generate a One Time Password (OTP) and send it to the specified phone number, with optional branding.

post/generate_otp

Request

  • Base URL: https://api.myotp.app
  • URL: https://api.myotp.app/generate_otp
  • Auth: none declared. Required headers: X-API-Key

Headers

X-API-Keystring required

API key for authentication.

Request body

phone_numberstring required

Phone number to send the OTP to. E.164 format. Include country code without any prefixes.

otp_lengthinteger

Length of the OTP, defaults to 6. 3 to 8 digits (4 to 8 on Telegram).

otp_validityinteger

Seconds the OTP stays valid, defaults to 300. 30 to 14400 (up to 3600 on Telegram). On WhatsApp the template's expiry applies instead.

channel'sms' | 'whatsapp' | 'telegram'

Delivery channel for the OTP. Defaults to 'sms'. For WhatsApp, ensure the destination supports WhatsApp Business messaging. Telegram is delivered through the Telegram Gateway API and is charged at a flat rate in every country.

template_orderinteger

Order of the template to be used for the OTP message, defaults to 1 (12 for WhatsApp). WhatsApp templates: 12 = English, 5-minute code; 13 = English, 10 minutes; 14 = Spanish (es_MX), 5 minutes; 15 = Spanish (es_MX), 10 minutes. The template's expiry overrides otp_validity on WhatsApp. Requires the ACCESS_TO_TEMPLATES entitlement (Business and Enterprise plans and the free trial).

otp_codestring

Supply your own code instead of letting MyOTP generate one (3 to 8 digits, 4 to 8 for telegram). When set, otp_length is ignored. Use this when another system (for example an identity provider) already holds the code the user must type.

force_sendboolean

If true, forces the sending of OTP even if there is an existing, unexpired OTP for the given phone number.

return_otpboolean

If true, includes the OTP value in the response. CAUTION: this is not compliant with regulations in many markets.

brandstring

Optional brand name for personalizing the OTP message. 3 to 16 characters, letters, digits and dots. Brand names are screened against a denylist to prevent impersonation. CAUTION: This overrides the account and app defaults.

Response

OTP successfully generated and sent.

message_idstring

ID of the message sent.

status'accepted'

Status of the request. Always "accepted" on a 200; delivery state comes from /check_otp_status or a delivery webhook.

messagestring

Message describing the status of the request.

date_sentstring date-time

Date and time the OTP was sent.

expires_atstring date-time

Date and time the OTP expires.

costnumber float

Cost of sending the OTP.

otpstring

The OTP value, included if return_otp is true.

Changes

No recorded changes to this operation across all 1 revision of this API.